Skip to content

Commit b82195d

Browse files
authored
Implement @JsonInclude(content= (#1050)
1 parent be4a491 commit b82195d

File tree

12 files changed

+1223
-199
lines changed

12 files changed

+1223
-199
lines changed

serde-api/src/main/java/io/micronaut/serde/config/annotation/SerdeConfig.java

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
*/
9393
String INCLUDE = "include";
9494

95+
/**
96+
* Include content strategy.
97+
*/
98+
String INCLUDE_CONTENT = "includeContent";
99+
95100
/**
96101
* Property filter name.
97102
*/

serde-jackson-tck/src/main/groovy/io/micronaut/serde/jackson/JsonGetterSetterSpec.groovy

+49
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,55 @@ package io.micronaut.serde.jackson
1717

1818
abstract class JsonGetterSetterSpec extends JsonCompileSpec {
1919

20+
void "test json any getter / setter - records"() {
21+
given:
22+
def context = buildContext('''
23+
package jsongetterrecord;
24+
25+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
26+
import com.fasterxml.jackson.annotation.JsonAnySetter;
27+
import com.fasterxml.jackson.annotation.JsonSetter;
28+
import io.micronaut.core.annotation.Introspected;
29+
import io.micronaut.serde.annotation.Serdeable;
30+
import com.fasterxml.jackson.annotation.JsonGetter;
31+
import java.util.*;
32+
33+
@Serdeable
34+
record Test(
35+
String name,
36+
@JsonAnyGetter
37+
@JsonAnySetter
38+
Map<String, Object> attributes) {
39+
}
40+
''')
41+
42+
def argument = argumentOf(context, 'jsongetterrecord.Test')
43+
44+
when:
45+
def bean = newInstance(context, 'jsongetterrecord.Test', "Fred", [foo:'bar', age: 10])
46+
def result = writeJson(jsonMapper, bean)
47+
48+
then:
49+
result == '{"name":"Fred","foo":"bar","age":10}'
50+
51+
when:
52+
bean = jsonMapper.readValue(result, argument)
53+
54+
then:
55+
bean.name == "Fred"
56+
bean.attributes == [foo:'bar', age:10]
57+
58+
when:
59+
bean = jsonMapper.readValue('{"name":"Fred","age":45,"wgt":100}', argument)
60+
61+
then:
62+
bean.name == "Fred"
63+
bean.attributes == [age:45, wgt:100]
64+
65+
cleanup:
66+
context.close()
67+
}
68+
2069
void "@JsonAnyGetter"() {
2170
given:
2271
def context = buildContext('example.Test', '''

0 commit comments

Comments
 (0)