如何使用spring-boot在我的杰克逊解串器中包含Objeto根?
我尝试放入application.properties
spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true
我尝试使用一个配置器
@Configuration public class JacksonConfig { @Bean public Jackson2ObjectMapperBuilder jacksonBuilder() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.featuresToEnable(DeserializationFeature.UNWRAP_ROOT_VALUE); builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")); builder.indentOutput(true); return builder; } }
我在课堂上添加了注释
@JsonRootName("contato") public class TbContato extends EntityBase {
但不工作,我得到了这个回报:
{ "cdContato": 12, "dtContato": "03/08/2015 16:04:43", "cdUsuario": null, "nmParte": "Fabio Ebner", "nmEmailParte": "fabioebner@gmail.com", "nmAssunto": "Assuntttoooo", "dsMensagem": "mensagem nessa porra aqui", "dtResposta": null, "dsResposta": null, "cdUsuarioResposta": null, "nmUsuarioResposta": null }
没有根。
那是因为您要序列化而不是反序列化。尝试使用
spring.jackson.serialization.WRAP_ROOT_VALUE=true