my goal is to configure the objectMapper
in the way that it only serialises element which are annotated with @JsonProperty
.
In order to do
If you want to add custom ObjectMapper for registering custom serializers, try my answer.
In my case (Spring 3.2.4 and Jackson 2.3.1), XML configuration for custom serializer:
was in unexplained way overwritten back to default by something.
This worked for me:
@JsonSerialize(using = CustomObjectSerializer.class)
public class CustomObject {
private Long value;
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}
public class CustomObjectSerializer extends JsonSerializer {
@Override
public void serialize(CustomObject value, JsonGenerator jgen,
SerializerProvider provider) throws IOException,JsonProcessingException {
jgen.writeStartObject();
jgen.writeNumberField("y", value.getValue());
jgen.writeEndObject();
}
@Override
public Class handledType() {
return CustomObject.class;
}
}
No XML configuration (
) is needed in my solution.