Skip to content

Commit 928d356

Browse files
fxshleinmanusa
andcommitted
fix(model): use SettableBeanProperty.Delegating for jackson delegation (6343)
fix(model): Use SettableBeanProperty.Delegating for jackson delegation Changes the delegation in SettableBeanPropertyDelegate from a custom implementation to the standard way of implementing a delegating property in jackson. This way, if some jackson module overrides methods that are not delegated explicitely here, they will continue to work. Fixes: #6342 --- fix: SettableBeanProperty.deserializeSetAndReturn should return instance instead of null Signed-off-by: Marc Nuri <[email protected]> --- test:refactor: SettableBeanPropertyDelegateTest doesn't rely on mocks Signed-off-by: Marc Nuri <[email protected]> --- fix: SettableBeanPropertyDelegate implements all methods from SettableBeanProperty Includes tests to ensure all methods are implemented in future Jackson versions too. Signed-off-by: Marc Nuri <[email protected]> Co-authored-by: Marc Nuri <[email protected]> Signed-off-by: Marc Nuri <[email protected]>
1 parent 9e105cb commit 928d356

File tree

3 files changed

+479
-133
lines changed

3 files changed

+479
-133
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#### Bugs
66
* Fix #6247: Support for proxy authentication from proxy URL user info
7-
7+
* Fix #6342: UnmatchedFieldTypeModule prevents certain jackson features from working
88

99
### 6.13.3 (2024-08-13)
1010

kubernetes-model-generator/kubernetes-model-common/src/main/java/io/fabric8/kubernetes/model/jackson/SettableBeanPropertyDelegate.java

+73-40
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@
1616
package io.fabric8.kubernetes.model.jackson;
1717

1818
import com.fasterxml.jackson.core.JsonParser;
19-
import com.fasterxml.jackson.databind.DeserializationConfig;
2019
import com.fasterxml.jackson.databind.DeserializationContext;
21-
import com.fasterxml.jackson.databind.JsonDeserializer;
20+
import com.fasterxml.jackson.databind.JavaType;
21+
import com.fasterxml.jackson.databind.JsonMappingException;
2222
import com.fasterxml.jackson.databind.PropertyName;
23+
import com.fasterxml.jackson.databind.SerializerProvider;
2324
import com.fasterxml.jackson.databind.deser.NullValueProvider;
2425
import com.fasterxml.jackson.databind.deser.SettableAnyProperty;
2526
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
2627
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
27-
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
28+
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
29+
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
2830

2931
import java.io.IOException;
3032
import java.lang.annotation.Annotation;
3133
import java.util.function.BooleanSupplier;
3234

3335
/**
34-
* This concrete sub-class encapsulates a {@link SettableBeanProperty} delegate that is always tried first.
36+
* This concrete subclass encapsulates a {@link SettableBeanProperty} delegate that is always tried first.
3537
*
3638
* <p>
3739
* A fall-back mechanism is implemented in the deserializeAndSet methods to allow field values that don't match the
3840
* target type to be preserved in the anySetter method if exists.
3941
*/
40-
public class SettableBeanPropertyDelegate extends SettableBeanProperty {
42+
public class SettableBeanPropertyDelegate extends SettableBeanProperty.Delegating {
4143

42-
private final SettableBeanProperty delegate;
4344
private final SettableAnyProperty anySetter;
4445
private final transient BooleanSupplier useAnySetter;
4546

4647
SettableBeanPropertyDelegate(SettableBeanProperty delegate, SettableAnyProperty anySetter, BooleanSupplier useAnySetter) {
4748
super(delegate);
48-
this.delegate = delegate;
4949
this.anySetter = anySetter;
5050
this.useAnySetter = useAnySetter;
5151
}
@@ -54,64 +54,113 @@ public class SettableBeanPropertyDelegate extends SettableBeanProperty {
5454
* {@inheritDoc}
5555
*/
5656
@Override
57-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
58-
return new SettableBeanPropertyDelegate(delegate.withValueDeserializer(deser), anySetter, useAnySetter);
57+
protected SettableBeanProperty withDelegate(SettableBeanProperty d) {
58+
return new SettableBeanPropertyDelegate(d, anySetter, useAnySetter);
5959
}
6060

6161
/**
6262
* {@inheritDoc}
6363
*/
6464
@Override
65-
public SettableBeanProperty withName(PropertyName newName) {
66-
return new SettableBeanPropertyDelegate(delegate.withName(newName), anySetter, useAnySetter);
65+
public void markAsIgnorable() {
66+
delegate.markAsIgnorable();
6767
}
6868

6969
/**
7070
* {@inheritDoc}
7171
*/
7272
@Override
73-
public SettableBeanProperty withNullProvider(NullValueProvider nva) {
74-
return new SettableBeanPropertyDelegate(delegate.withNullProvider(nva), anySetter, useAnySetter);
73+
public boolean isIgnorable() {
74+
return delegate.isIgnorable();
7575
}
7676

7777
/**
7878
* {@inheritDoc}
7979
*/
8080
@Override
81-
public AnnotatedMember getMember() {
82-
return delegate.getMember();
81+
public void setViews(Class<?>[] views) {
82+
delegate.setViews(views);
8383
}
8484

8585
/**
8686
* {@inheritDoc}
8787
*/
8888
@Override
89-
public <A extends Annotation> A getAnnotation(Class<A> acls) {
90-
return delegate.getAnnotation(acls);
89+
public <A extends Annotation> A getContextAnnotation(Class<A> acls) {
90+
return delegate.getContextAnnotation(acls);
9191
}
9292

9393
/**
9494
* {@inheritDoc}
9595
*/
9696
@Override
97-
public void fixAccess(DeserializationConfig config) {
98-
delegate.fixAccess(config);
97+
public PropertyName getWrapperName() {
98+
return delegate.getWrapperName();
9999
}
100100

101101
/**
102102
* {@inheritDoc}
103103
*/
104104
@Override
105-
public void markAsIgnorable() {
106-
delegate.markAsIgnorable();
105+
public NullValueProvider getNullValueProvider() {
106+
return delegate.getNullValueProvider();
107107
}
108108

109109
/**
110110
* {@inheritDoc}
111111
*/
112112
@Override
113-
public boolean isIgnorable() {
114-
return delegate.isIgnorable();
113+
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor, SerializerProvider provider)
114+
throws JsonMappingException {
115+
delegate.depositSchemaProperty(objectVisitor, provider);
116+
}
117+
118+
/**
119+
* {@inheritDoc}
120+
*/
121+
@Override
122+
public JavaType getType() {
123+
return delegate.getType();
124+
}
125+
126+
/**
127+
* {@inheritDoc}
128+
*/
129+
@Override
130+
public PropertyName getFullName() {
131+
return delegate.getFullName();
132+
}
133+
134+
/**
135+
* {@inheritDoc}
136+
*/
137+
@Override
138+
public void setManagedReferenceName(String n) {
139+
delegate.setManagedReferenceName(n);
140+
}
141+
142+
/**
143+
* {@inheritDoc}
144+
*/
145+
@Override
146+
public SettableBeanProperty withSimpleName(String simpleName) {
147+
return _with(delegate.withSimpleName(simpleName));
148+
}
149+
150+
/**
151+
* {@inheritDoc}
152+
*/
153+
@Override
154+
public void setObjectIdInfo(ObjectIdInfo objectIdInfo) {
155+
delegate.setObjectIdInfo(objectIdInfo);
156+
}
157+
158+
/**
159+
* {@inheritDoc}
160+
*/
161+
@Override
162+
public String toString() {
163+
return delegate.toString();
115164
}
116165

117166
/**
@@ -151,23 +200,7 @@ public Object deserializeSetAndReturn(JsonParser p, DeserializationContext ctxt,
151200
} catch (MismatchedInputException ex) {
152201
deserializeAndSet(p, ctxt, instance);
153202
}
154-
return null;
155-
}
156-
157-
/**
158-
* {@inheritDoc}
159-
*/
160-
@Override
161-
public void set(Object instance, Object value) throws IOException {
162-
delegate.set(instance, value);
163-
}
164-
165-
/**
166-
* {@inheritDoc}
167-
*/
168-
@Override
169-
public Object setAndReturn(Object instance, Object value) throws IOException {
170-
return delegate.setAndReturn(instance, value);
203+
return instance;
171204
}
172205

173206
private boolean shouldUseAnySetter() {

0 commit comments

Comments
 (0)