0

How can jackson MappingJackson2HttpMessageConverter converte a pogo into a json without @JSONProperty ON every Property?

I use groovy in spring boot project and no java code, I hava a domain model named FileInfo.groovy:

class FileInfo {
    private String name

    @JsonProperty("is_dir")
    private boolean isDirectory

    @JsonProperty("last_modified")
    private String lastModifiedTime
}

I configured MappingJackson2HttpMessageConverter in @Configuration @EnableWebMvc class.

and when return a FileInfo in controller handler with @ResponseBody,THERE is no name in result json;

I know the pogo property is accessed by public void setProperty(java.lang.String, java.lang.Object);

So are there a annotation on class that can mark a pogo that can convert by jackson? cuz it is too noisy use @JSONProperty on every property.

WesleyHsiung
  • 351
  • 2
  • 13

1 Answers1

0

See this question. The question shows how to set the visibility for a class and the accepted answer shows how to set the visibility for an entire ObjectMapper.

The idea is to set the field visibility to Visibility.ANY to pick up private fields.

Community
  • 1
  • 1
Jon Peterson
  • 2,966
  • 24
  • 32