List of usage examples for com.fasterxml.jackson.annotation PropertyAccessor FIELD
PropertyAccessor FIELD
To view the source code for com.fasterxml.jackson.annotation PropertyAccessor FIELD.
Click Source Link
From source file:com.josue.ws.web.server.MessageDispatcher.java
@PostConstruct public void init() { mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); }
From source file:com.josue.kingdom.rest.CustomJacksonProvider.java
public CustomJacksonProvider() { LOG.info("*********** CUSTOMJACKSONPROVIDER ***********"); mapper = new ObjectMapper(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); //Field Access... ref: http://stackoverflow.com/questions/7105745/how-to-specify-jackson-to-only-use-fields-preferably-globally mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); }
From source file:it.bz.tis.integreen.carsharingbzit.tis.FakeConnector.java
public FakeConnector() { this.mapper = new ObjectMapper(); this.mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); this.mapper.enable(SerializationFeature.INDENT_OUTPUT); }
From source file:com.braisgabin.fbstats.Api.java
public Api(String accessToken) { this.accessToken = accessToken; this.client = new OkHttpClient(); this.mapper = new ObjectMapper(); this.mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); this.mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE); this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true); }
From source file:com.raythos.sentilexo.persistence.cql.PersistedEntity.java
public static PersistedEntity fromBinaryJSon(byte[] data, Class classType) { try {/*from w w w .j a v a 2 s .c o m*/ SmileFactory f = new SmileFactory(); f.configure(SmileParser.Feature.REQUIRE_HEADER, true); ObjectMapper mapper = new ObjectMapper(f); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); Object result = mapper.readValue(data, classType); return (PersistedEntity) result; } catch (IOException ex) { Logger.getLogger(PersistedEntity.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:test.com.wealdtech.jackson.modules.WealdMapperTest.java
@Test public void testSerLong() throws Exception { final TestLongClass testClass = new TestLongClass(1000000000000L); final ObjectMapper mapper = WealdMapper.getMapper().copy(); assertEquals(mapper.writeValueAsString(testClass), "{\"val\":1000000000000}"); final ObjectMapper serverMapper = WealdMapper.getServerMapper().copy(); assertEquals(serverMapper.writeValueAsString(testClass), "{\"val\":1000000000000}"); final ObjectMapper simpleMapper = new ObjectMapper().copy().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); assertEquals(simpleMapper.writeValueAsString(testClass), "{\"val\":1000000000000}"); }
From source file:com.tomtom.speedtools.json.JsonObjectMapperFactory.java
public static ObjectMapper createJsonObjectMapper() { // Create a Json factory with customer properties. final JsonFactory jsonFactory = new JsonFactory(); // Json parsing features. jsonFactory.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); // Json generation features. jsonFactory.configure(Feature.QUOTE_FIELD_NAMES, true).configure(Feature.WRITE_NUMBERS_AS_STRINGS, false); // Create a custom object mapper from the newly created factory. This object mapper will be used by RestEasy. final ObjectMapper mapper = new ObjectMapper(jsonFactory); // Set generic mapper configuration. mapper.configure(MapperFeature.USE_ANNOTATIONS, true).configure(MapperFeature.AUTO_DETECT_GETTERS, false) .configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false) .configure(MapperFeature.AUTO_DETECT_SETTERS, false) .configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY).setSerializationInclusion(Include.NON_NULL) .disableDefaultTyping().disable(SerializationFeature.WRITE_NULL_MAP_VALUES); // Set deserialization configuration. mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); // Set serialization configuration. mapper.configure(SerializationFeature.INDENT_OUTPUT, false) .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true) .configure(SerializationFeature.WRAP_ROOT_VALUE, false) .configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, false) .configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true) .configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, false); // The annotation inspectors and additional mappers should be set by the caller. return mapper; }
From source file:com.epam.marshaller.jackson.JacksonMarshallerTest.java
private ObjectMapper prepareObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); objectMapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS); objectMapper.enable(MapperFeature.AUTO_DETECT_FIELDS); objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); objectMapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE); objectMapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE); objectMapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE); return objectMapper; }
From source file:jp.classmethod.aws.brian.util.BrianClientObjectMapper.java
/** * Instantiate.// w ww.j a v a 2 s.c o m */ public BrianClientObjectMapper() { SimpleModule brianModule = new SimpleModule("brianClientModule", VERSION); registerModule(brianModule); registerModule(new Jdk8Module()); configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); setVisibility(PropertyAccessor.FIELD, Visibility.ANY); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(TimeZone.getTimeZone("Universal")); setDateFormat(df); }
From source file:com.heisenberg.impl.json.JacksonJsonService.java
public JacksonJsonService(ServiceRegistry serviceRegistry) { this.objectMapper = serviceRegistry.getService(ObjectMapper.class); this.jsonFactory = serviceRegistry.getService(JsonFactory.class); objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) .setVisibility(PropertyAccessor.ALL, Visibility.NONE) .setVisibility(PropertyAccessor.FIELD, Visibility.ANY).setSerializationInclusion(Include.NON_EMPTY); SimpleModule module = new SimpleModule(); module.addSerializer(new LocalDateTimeSerializer()); module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer()); objectMapper.registerModule(module); }