Skip to content

Commit 696bcd8

Browse files
authored
Merge branch '2.x' into 2.x
2 parents 0f42bc9 + 67135f7 commit 696bcd8

File tree

14 files changed

+294
-11
lines changed

14 files changed

+294
-11
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ public SettableAnyProperty withValueDeserializer(JsonDeserializer<Object> deser)
496496
}
497497
}
498498

499-
500499
/**
501500
* [databind#562] Allow @JsonAnySetter on Creator constructor
502501
*
@@ -539,7 +538,6 @@ protected void _set(Object instance, Object propName, Object value)
539538

540539
@Override
541540
public Object createParameterObject() { return new HashMap<>(); }
542-
543541
}
544542

545543
/**
@@ -590,7 +588,5 @@ public SettableAnyProperty withValueDeserializer(JsonDeserializer<Object> deser)
590588

591589
@Override
592590
public Object createParameterObject() { return _nodeFactory.objectNode(); }
593-
594591
}
595-
596592
}

src/main/java/com/fasterxml/jackson/databind/ser/ContainerSerializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* {@link java.util.Collection}s (<code>Lists</code>, <code>Sets</code>
1111
* etc) and {@link java.util.Map}s and iterable things
1212
* ({@link java.util.Iterator}s).
13+
*<p>
14+
* NOTE: in Jackson 3.x, this class is renamed {@code StdContainerSerializer}
15+
* (in package {@code tools.jackson.databind.ser.std}).
1316
*/
1417
@SuppressWarnings("serial")
1518
public abstract class ContainerSerializer<T>
@@ -35,8 +38,6 @@ protected ContainerSerializer(JavaType fullType) {
3538
/**
3639
* Alternate constructor that is (alas!) needed to work
3740
* around kinks of generic type handling
38-
*
39-
* @param t
4041
*/
4142
protected ContainerSerializer(Class<?> t, boolean dummy) {
4243
super(t, dummy);

src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumDefaultReadTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ enum MixinOverloadedDefault {
7979
A,
8080
@JsonEnumDefaultValue
8181
B,
82-
@JsonEnumDefaultValue
82+
// Let's leave one un-annotated:
8383
C,
8484
@JsonEnumDefaultValue
8585
Z;
@@ -305,7 +305,9 @@ public void testFirstEnumDefaultValueViaMixin() throws Exception
305305
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
306306
.addMixIn(BaseOverloaded.class, MixinOverloadedDefault.class)
307307
.build();
308-
308+
309+
// While not guaranteed by annotation Javadocs, default implementation does
310+
// pick the first annotated enum value (in declaration order))
309311
assertEquals(BaseOverloaded.A,
310312
mixinMapper.readValue(q("UNKNOWN"), BaseOverloaded.class));
311313
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.fasterxml.jackson.databind.ext;
2+
3+
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import java.util.Collections;
7+
import java.util.Map;
8+
9+
import org.hibernate.repackage.cglib.MockedHibernateCglibProxy;
10+
import org.junit.jupiter.api.Test;
11+
import org.springframework.cglib.proxy.MockedSpringCglibProxy;
12+
13+
import com.fasterxml.jackson.databind.ObjectMapper;
14+
15+
import net.sf.cglib.MockedNetCglibProxy;
16+
17+
// [databind#5354] Test for filtering out CGLIB-generated properties
18+
public class CglibFiltering5354Test
19+
{
20+
private final ObjectMapper MAPPER = newJsonMapper();
21+
22+
// https://github.com/FasterXML/jackson-databind/issues/5354
23+
@Test
24+
public void testWriteWithSpringCglibProxyDoesNotIncludeCallbacksProperty() throws Exception
25+
{
26+
MockedSpringCglibProxy mockedProxy = new MockedSpringCglibProxy("hello");
27+
String json = MAPPER.writeValueAsString(mockedProxy);
28+
Map<?, ?> properties = MAPPER.readValue(json, Map.class);
29+
assertEquals(properties.keySet(), Collections.singleton("propertyName"));
30+
}
31+
32+
// https://github.com/FasterXML/jackson-databind/issues/5354
33+
@Test
34+
public void testWriteWithHibernateCglibProxyDoesNotIncludeCallbacksProperty() throws Exception
35+
{
36+
MockedHibernateCglibProxy mockedProxy = new MockedHibernateCglibProxy("hello");
37+
String json = MAPPER.writeValueAsString(mockedProxy);
38+
Map<?, ?> properties = MAPPER.readValue(json, Map.class);
39+
assertEquals(properties.keySet(), Collections.singleton("propertyName"));
40+
}
41+
42+
// https://github.com/FasterXML/jackson-databind/issues/5354
43+
@Test
44+
public void testWriteWithNetCglibProxyDoesNotIncludeCallbacksProperty() throws Exception
45+
{
46+
MockedNetCglibProxy mockedProxy = new MockedNetCglibProxy("hello");
47+
String json = MAPPER.writeValueAsString(mockedProxy);
48+
Map<?, ?> properties = MAPPER.readValue(json, Map.class);
49+
assertEquals(properties.keySet(), Collections.singleton("propertyName"));
50+
}
51+
52+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.fasterxml.jackson.databind.misc;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
7+
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.json.JsonMapper;
9+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
// [databind#5335]
14+
public class IPhoneStyleProperty5335Test
15+
extends DatabindTestUtil
16+
{
17+
@JsonPropertyOrder({"aProp", "anotherProp"})
18+
static class TestPojo {
19+
private String aProp;
20+
private String anotherProp;
21+
22+
public String getaProp() {
23+
return aProp;
24+
}
25+
26+
public void setaProp(String aProp) {
27+
this.aProp = aProp;
28+
}
29+
30+
public String getAnotherProp() {
31+
return anotherProp;
32+
}
33+
34+
public void setAnotherProp(String anotherProp) {
35+
this.anotherProp = anotherProp;
36+
}
37+
}
38+
39+
@Test
40+
public void featureEnabledTest() throws Exception
41+
{
42+
ObjectMapper mapper = JsonMapper.builder()
43+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
44+
.enable(MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX)
45+
.build();
46+
47+
String json = "{\"aProp\":\"aPropValue\",\"prop1\":\"prop1Value\"}";
48+
TestPojo result = mapper.readValue(json, TestPojo.class);
49+
assertEquals("aPropValue", result.getaProp());
50+
String serialized = mapper.writeValueAsString(result);
51+
assertEquals("{\"aProp\":\"aPropValue\",\"anotherProp\":null}",
52+
serialized);
53+
}
54+
}

src/test/java/com/fasterxml/jackson/databind/ser/AnyGetterOrdering4388Test.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ static class PojoUnwrappedVersion1 extends BaseWithProperties {
4747
@JsonPropertyOrder({"entityId", "totalTests", "childEntities", "entityName", "products"})
4848
static class PojoUnwrappedVersion2 extends BaseWithProperties {
4949
}
50-
50+
51+
@JsonPropertyOrder({"child1", "child2"})
5152
static class Location {
5253
public int child1;
5354
public int child2;
@@ -60,6 +61,7 @@ static class IgnorePropertiesOnFieldPojo {
6061
public Map<String, Object> map = new HashMap<>();
6162
}
6263

64+
@JsonPropertyOrder({"a", "b"})
6365
static class IgnorePropertiesOnAnyGetterPojo {
6466
public int a = 1, b = 2;
6567
@JsonIgnoreProperties("b")

src/test/java/com/fasterxml/jackson/databind/ser/enums/EnumAsFormatObject4564Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import com.fasterxml.jackson.annotation.JsonFormat;
99
import com.fasterxml.jackson.annotation.JsonInclude;
10-
10+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
1111
import com.fasterxml.jackson.core.JsonProcessingException;
1212
import com.fasterxml.jackson.core.type.TypeReference;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -18,9 +18,9 @@
1818
// [databind#4564] Fix Enum-asJSON-Object serialization with self as field.
1919
public class EnumAsFormatObject4564Test
2020
{
21-
2221
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
2322
@JsonInclude(JsonInclude.Include.NON_NULL)
23+
@JsonPropertyOrder({"label", "sublevel"})
2424
public enum Level {
2525
LEVEL1("level1"),
2626
LEVEL2("level2"),
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.fasterxml.jackson.databind.tofix;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import com.fasterxml.jackson.annotation.*;
7+
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
10+
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
14+
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertNotNull;
17+
18+
// [databind#5342] JsonAnyGetter method serialization can override JsonProperty serialization on serialized name conflict
19+
public class AnyGetterNameConflictSerialization5342Test
20+
extends DatabindTestUtil
21+
{
22+
public static class Pojo5342 {
23+
@JsonIgnore
24+
private Map<String, Object> additionalProperties;
25+
@JsonProperty(value = "additionalProperties")
26+
private Map<String, Object> hidden;
27+
28+
@JsonAnySetter
29+
private void additionalProperties(String key, Object value) {
30+
if (additionalProperties == null) {
31+
additionalProperties = new HashMap<>();
32+
}
33+
additionalProperties.put(key.replace("\\.", "."), value);
34+
}
35+
36+
@JsonAnyGetter
37+
public Map<String, Object> additionalProperties() {
38+
return additionalProperties;
39+
}
40+
41+
public Map<String, Object> hidden() {
42+
return hidden;
43+
}
44+
45+
public void hidden(Map<String, Object> additionalPropertiesProperty) {
46+
this.hidden = additionalPropertiesProperty;
47+
}
48+
}
49+
50+
private final ObjectMapper MAPPER = newJsonMapper();
51+
52+
@JacksonTestFailureExpected
53+
@Test
54+
public void anyGetter5342()
55+
throws Exception
56+
{
57+
Pojo5342 pojo = new Pojo5342();
58+
pojo.additionalProperties("foo", "bar");
59+
60+
Map<String, Object> hidden = new HashMap<>();
61+
hidden.put("fizz", "buzz");
62+
pojo.hidden(hidden);
63+
64+
65+
String JSON = MAPPER.writeValueAsString(pojo);
66+
// was in 2.18 : {"foo":"bar","additionalProperties": {"fizz":"buzz"}}
67+
// now in 2.19 : {"foo":"bar"}... need FIX!
68+
// any-getter
69+
assertThat(JSON).contains("\"foo\":\"bar\"");
70+
// hidden field
71+
assertThat(JSON).contains("\"additionalProperties\":{\"fizz\":\"buzz\"}");
72+
73+
// Try deserializing back
74+
Pojo5342 actual = MAPPER.readValue(JSON, Pojo5342.class);
75+
assertNotNull(actual.additionalProperties());
76+
assertEquals(1, actual.additionalProperties.size());
77+
assertNotNull(actual.hidden());
78+
assertEquals(1, actual.hidden().size());
79+
}
80+
81+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.sf.cglib;
2+
3+
/**
4+
* A mock object to test if a method is returning cglib's
5+
* {@code Callback[] getCallbacks()} found on a cglib proxy object.
6+
* @author Rob Winch
7+
*/
8+
public class Callback {
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package net.sf.cglib;
2+
3+
/**
4+
* A mock Proxy object used to test writing a cglib proxy object.
5+
* @author Rob Winch
6+
*/
7+
public class MockedNetCglibProxy {
8+
9+
private final String propertyName;
10+
11+
public MockedNetCglibProxy(String propertyName) {
12+
this.propertyName = propertyName;
13+
}
14+
15+
public String getPropertyName() {
16+
return this.propertyName;
17+
}
18+
19+
public Callback[] getCallbacks() {
20+
return new Callback[] { new Callback(), new Callback() };
21+
}
22+
}

0 commit comments

Comments
 (0)