fasterxml jackson: there is no necessary methods to use @JsonView functionality

StackOverflow https://stackoverflow.com/questions/17924719

  •  04-06-2022
  •  | 
  •  

سؤال

I try to organize dynamic @JsonIgnore property when I convert java-object to json-string. In example it works in next way for (codehause jackson) ObjectMapper oMapper = new ObjectMapper(); oMapper.setSerializationConfig(...

or in example for fasterxml objectMapper.getSerializationConfig().setSerializationView(

PROBLEM: bolded method are absent in my jackson:

pom.xml

<jackson.version>2.1.1</jackson.version>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>${jackson.version}</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>${jackson.version}</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
  <version>${jackson.version}</version>
</dependency>
هل كانت مفيدة؟

المحلول

Have a look at ObjectWriter and ObjectReader which do include functionality for setting active view to use. This is different from Jackson 1.x, which exposed them through SerializationConfig and DeserializationConfig. You can construct these objects from ObjectMapper (mapper.readerXxx() and mapper.writerXxx()); they are reusable, and offer more thread-safe configurability than ObjectMapper.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top