Jackson JSON: Enabling Top Level Segment

I mean this post: convert json to an object using jackson , and the last answer is StaxMan, which says that in Jackson 1.7 you can set the configuration so that Jackson starts to produce (and maybe parsing too?) Tag / segment top level in JSON.

Can someone shed some light on how to configure this configuration, and this is only for JSON generation or analysis?

Many thanks!

+5
source share
1 answer

You need to create and configure ObjectMapperusing a function WRAP_ROOT_VALUElike

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);

See javadoc :

, root ( JSON Object, ), JSON , " ", (, JAXB, @XmlRootElement.name) ( ). JAXB.

- false, .

Javadoc , , , Jackson, . .

+4

All Articles