List of usage examples for com.fasterxml.jackson.core Version Version
@Deprecated public Version(int major, int minor, int patchLevel, String snapshotInfo)
From source file:com.company.et.service.JsonService.java
public static Professor[] jsonToObjectProfessorArray(String json) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); List<String> json_list = split(json); Professor[] profs = new Professor[json_list.size()]; SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)) .addDeserializer(Professor.class, new ProfessorDeserializer()); mapper.registerModule(testModule);/*from w ww . ja v a 2s. c om*/ for (int i = 0; i < json_list.size(); i++) { //System.out.println(json_list.get(i)); profs[i] = mapper.readValue(json_list.get(i), Professor.class); } return profs; }
From source file:br.com.criativasoft.opendevice.core.json.CommandJacksonMapper.java
public ObjectMapper getMapper() { if (mapper == null) { mapper = new ObjectMapper(); // Uses Enum.toString() for serialization of an Enum mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); // Uses Enum.toString() for deserialization of an Enum mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); SimpleModule module = new SimpleModule("OpenDeviceModule", new Version(0, 1, 0, "alpha")); module.addSerializer(CommandType.class, new EnumCodeSerializer()); module.addDeserializer(CommandType.class, new EnumCodeDeserialize.CommandTypeDeserialize()); mapper.registerModule(module);/*from w ww . j a v a 2 s.c om*/ module.addDeserializer(Command.class, new CommandDeserialize()); //mapper.enableDefaultTyping(); //mapper.setDefaultTyping(new ObjectMapper.DefaultTypeResolverBuilder()); // // List<Class<? extends Command>> classList = new ArrayList<Class<? extends Command>>(); // classList.add(Command.class); // classList.add(ResponseCommand.class); // classList.add(GetDevicesCommand.class); // // for (Class<? extends Command> aClass : classList) { // mapper.addMixInAnnotations(aClass, JsonCommand.class); // } //mapper.getSubtypeResolver().registerSubtypes(new NamedType()); } return mapper; }
From source file:org.mongojack.internal.MongoJackModule.java
@Override public Version version() { return new Version(1, 0, 0, null); }
From source file:gaffer.serialisation.json.hyperloglogplus.HyperLogLogPlusJsonSerialisationTest.java
@Before public void before() { mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); final SimpleModule module = new SimpleModule( HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SERIALISER_MODULE_NAME, new Version(1, 0, 0, null)); module.addSerializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonSerialiser()); module.addDeserializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonDeserialiser()); mapper.registerModule(module);/*from www. j a va 2s. co m*/ }
From source file:org.pentaho.metaverse.impl.model.kettle.json.KettleObjectMapper.java
public KettleObjectMapper(List<StdSerializer> serializers, List<StdDeserializer> deserializers) { mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.enable(SerializationFeature.WRAP_EXCEPTIONS); transModule = new SimpleModule("PDIModule", new Version(1, 0, 0, null)); if (!CollectionUtils.isEmpty(serializers)) { for (StdSerializer serializer : serializers) { transModule.addSerializer(serializer); }//from w ww . j av a 2s.c om } if (!CollectionUtils.isEmpty(deserializers)) { for (StdDeserializer deserializer : deserializers) { transModule.addDeserializer(deserializer.getValueClass(), deserializer); } } mapper.registerModule(transModule); }
From source file:ar.com.wolox.base.json.DateTimeJsonSerializationTest.java
/** Tests the serialization/deserialization process */ @Test// w w w. j ava 2 s .c o m public void testSerializationProcess() throws Exception { final DateTime date = new DateTime(1988, 11, 29, 12, 0); final ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); final SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)) .addDeserializer(DateTime.class, new DateTimeJsonDeserializer()) .addSerializer(DateTime.class, new DateTimeJsonSerializer()); mapper.registerModule(testModule); final String json = mapper.writeValueAsString(new Foo(date)); final Foo deserialized = mapper.readValue(json, Foo.class); assertEquals(date, deserialized.getDate()); }
From source file:it.eng.spagobi.behaviouralmodel.lov.service.GridMetadataContainer.java
/** * JSON serializer for this object//from w w w. j av a 2 s . com * @return the network serialized * @throws SerializationException */ @JsonIgnore public String toJSONString() throws it.eng.spagobi.commons.serializer.SerializationException { ObjectMapper mapper = new ObjectMapper(); String s = ""; try { SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, null)); simpleModule.addSerializer(GridMetadataContainer.class, new GridMetadataContainerJSONSerializer()); mapper.registerModule(simpleModule); s = mapper.writeValueAsString((GridMetadataContainer) this); } catch (Exception e) { throw new org.apache.commons.lang.SerializationException("Error serializing the network", e); } s = StringEscapeUtils.unescapeJavaScript(s); return s; }
From source file:be.wegenenverkeer.common.resteasy.json.RestJsonMapper.java
/** * Add a custom serializer./* ww w . j ava 2s.co m*/ * * @param classToMap class to map * @param classSerializer serializer * @param <T> class to map */ public <T> void addClassSerializer(Class<? extends T> classToMap, JsonSerializer<T> classSerializer) { SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)); testModule.addSerializer(classToMap, classSerializer); this.registerModule(testModule); }
From source file:org.agorava.yammer.jackson.YammerModule.java
public YammerModule() { super("YammerModule", new Version(1, 0, 0, null)); }
From source file:io.airlift.json.ObjectMapperProvider.java
@Override public ObjectMapper get() { ObjectMapper objectMapper = new ObjectMapper(); // ignore unknown fields (for backwards compatibility) objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // use ISO dates objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // skip fields that are null instead of writing an explicit json null value objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // disable auto detection of json properties... all properties must be explicit objectMapper.disable(MapperFeature.AUTO_DETECT_CREATORS); objectMapper.disable(MapperFeature.AUTO_DETECT_FIELDS); objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); objectMapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); objectMapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS); if (jsonSerializers != null || jsonDeserializers != null || keySerializers != null || keyDeserializers != null) { SimpleModule module = new SimpleModule(getClass().getName(), new Version(1, 0, 0, null)); if (jsonSerializers != null) { for (Entry<Class<?>, JsonSerializer<?>> entry : jsonSerializers.entrySet()) { addSerializer(module, entry.getKey(), entry.getValue()); }// w w w . ja v a2 s.c o m } if (jsonDeserializers != null) { for (Entry<Class<?>, JsonDeserializer<?>> entry : jsonDeserializers.entrySet()) { addDeserializer(module, entry.getKey(), entry.getValue()); } } if (keySerializers != null) { for (Entry<Class<?>, JsonSerializer<?>> entry : keySerializers.entrySet()) { addKeySerializer(module, entry.getKey(), entry.getValue()); } } if (keyDeserializers != null) { for (Entry<Class<?>, KeyDeserializer> entry : keyDeserializers.entrySet()) { module.addKeyDeserializer(entry.getKey(), entry.getValue()); } } modules.add(module); } for (Module module : modules) { objectMapper.registerModule(module); } return objectMapper; }