Closed
Description
Given the following class:
class Child2 {
public Object a1, b, a2;
@JsonCreator public Child2(/*Object a1,*/ Object b /*, Object a2*/) {}
}
The following Spock
test fails:
def "fields are sorted"() {
def objectMapper = new ObjectMapper()
.registerModule(new ParameterNamesModule())
.enable(SerializationFeature.CLOSE_CLOSEABLE)
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
def jsonBuffer = new ByteArrayOutputStream()
objectMapper.writeValue(jsonBuffer, new Child2(null))
def serialized = jsonBuffer.toString()
expect:
serialized == '{"a1":null,"a2":null,"b":null}'
}
fails, since it's serialized to the keys b
,a1
,a2
(uncommenting the first param, i.e. @JsonCreator public Child2(Object a1, Object b /*, Object a2*/) {}
would return a1
, b
,a2
).
While this may be a relatively stable solution (not even sure about that, since apparently constructor changes can affect the order), it's definitely not alphabetic.
Metadata
Metadata
Assignees
Labels
No labels