private void read(DataInput in) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); // define a module SimpleModule module = new SimpleModule("State Serializer", new Version(0, 1, 1, "FINAL")); // add the state deserializer module.addDeserializer(StatePair.class, new StateDeserializer()); // register the module with the object-mapper mapper.registerModule(module); JsonParser parser = mapper.getJsonFactory().createJsonParser((DataInputStream)in); StatePool statePool = mapper.readValue(parser, StatePool.class); this.setStates(statePool.getStates()); parser.close(); }
public JsonObjectMapperWriter(OutputStream output, boolean prettyPrint) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure( SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); // define a module SimpleModule module = new SimpleModule("Default Serializer", new Version(0, 1, 1, "FINAL")); // add various serializers to the module // add default (all-pass) serializer for all rumen specific data types module.addSerializer(DataType.class, new DefaultRumenSerializer()); // add a serializer to use object.toString() while serializing module.addSerializer(ID.class, new ObjectStringSerializer<ID>()); // register the module with the object-mapper mapper.registerModule(module); mapper.getJsonFactory(); writer = mapper.getJsonFactory().createJsonGenerator( output, JsonEncoding.UTF8); if (prettyPrint) { writer.useDefaultPrettyPrinter(); } }
private void write(DataOutput out) throws IOException { // This is just a JSON experiment System.out.println("Dumping the StatePool's in JSON format."); ObjectMapper outMapper = new ObjectMapper(); outMapper.configure( SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); // define a module SimpleModule module = new SimpleModule("State Serializer", new Version(0, 1, 1, "FINAL")); // add the state serializer //module.addSerializer(State.class, new StateSerializer()); // register the module with the object-mapper outMapper.registerModule(module); JsonFactory outFactory = outMapper.getJsonFactory(); JsonGenerator jGen = outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8); jGen.useDefaultPrettyPrinter(); jGen.writeObject(this); jGen.close(); }
/** * Search for any registered JsonDeserialize instances that have been declared using the * ServiceLoader. Add any found to the given mapper in a 'magic' module. */ private static void addDiscoverableDeserializers(final ObjectMapper mapper) { final ServiceLoader<JsonDeserializer> loader = ServiceLoader.load(JsonDeserializer.class); final Iterator<JsonDeserializer> iterator = loader.iterator(); final SimpleModule magic = new SimpleModule("magic", new Version(1, 0, 0, "")); while (iterator.hasNext()) { final JsonDeserializer<?> deserializer = iterator.next(); try { final Method deserialeMethod = deserializer.getClass() .getDeclaredMethod("deserialize", JsonParser.class, DeserializationContext.class); final Class<?> jsonType = deserialeMethod.getReturnType(); //noinspection unchecked magic.addDeserializer(jsonType, (JsonDeserializer) deserializer); } catch(Exception e) { throw new IllegalStateException(e); } } mapper.registerModule(magic); }
@Override public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception { log.info(" load() "); Meta meta = new Meta(); meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId()); meta.setResourceType("Schema"); schemaType.setMeta(meta); // Use serializer to walk the class structure ObjectMapper mapper = new ObjectMapper(); mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS); SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, "")); SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer(); serializer.setSchemaType(schemaType); userCoreLoadingStrategyModule.addSerializer(User.class, serializer); mapper.registerModule(userCoreLoadingStrategyModule); mapper.writeValueAsString(createDummyUser()); return serializer.getSchemaType(); }
@Override public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception { log.info(" load() "); Meta meta = new Meta(); meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId()); meta.setResourceType("Schema"); schemaType.setMeta(meta); // Use serializer to walk the class structure ObjectMapper mapper = new ObjectMapper(); mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS); SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, "")); SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer(); serializer.setSchemaType(schemaType); groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer); mapper.registerModule(groupCoreLoadingStrategyModule); mapper.writeValueAsString(createDummyGroup()); return serializer.getSchemaType(); }
@Override public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception { log.info(" load() "); Meta meta = new Meta(); meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId()); meta.setResourceType("Schema"); schemaType.setMeta(meta); // Use serializer to walk the class structure ObjectMapper mapper = new ObjectMapper(); mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS); SimpleModule userCoreLoadingStrategyModule = new SimpleModule("FidoDeviceCoreLoadingStrategyModule", new Version(1, 0, 0, "")); SchemaTypeFidoDeviceSerializer serializer = new SchemaTypeFidoDeviceSerializer(); serializer.setSchemaType(schemaType); userCoreLoadingStrategyModule.addSerializer(FidoDevice.class, serializer); mapper.registerModule(userCoreLoadingStrategyModule); mapper.writeValueAsString(createDummyFidoDevice()); return serializer.getSchemaType(); }
/** * Takes a JSON string that came from the frontend form submission and deserializes it into its {@link DataWrapper} dto * representation so that it can be converted to an MVEL expression * @param json * @return */ public DataWrapper convertJsonToDataWrapper(String json) { ObjectMapper mapper = new ObjectMapper(); DataDTODeserializer dtoDeserializer = new DataDTODeserializer(); SimpleModule module = new SimpleModule("DataDTODeserializerModule", new Version(1, 0, 0, null)); module.addDeserializer(DataDTO.class, dtoDeserializer); mapper.registerModule(module); if (json == null || "[]".equals(json)) { return null; } try { return mapper.readValue(json, DataWrapper.class); } catch (IOException e) { throw new RuntimeException(e); } }
private void addSerializers() { SimpleModule simpleModule = new SimpleModule("AHRDFModule", new Version(1,0, 0, null)); //simpleModule.addSerializer(new LangStringSerializer()); simpleModule.addSerializer(new XMLGregorianCalendarSerializer()); simpleModule.addSerializer(new OfferingSerializer()); simpleModule.addSerializer(EventType.class, new AHRDFObjectSerializer()); simpleModule.addSerializer(EventStatus.class, new AHRDFObjectSerializer()); simpleModule.addSerializer(Room.class, new AHRDFObjectSerializer()); simpleModule.addSerializer(AttachmentType.class, new AHRDFObjectSerializer()); simpleModule.addSerializer(ProductionType.class, new AHRDFObjectSerializer()); simpleModule.addSerializer(VenueType.class, new AHRDFObjectSerializer()); simpleModule.addSerializer(Genre.class, new AHRDFObjectSerializer()); registerModule(simpleModule); }
public QdsClientImpl(QdsConfiguration configuration) { this.configuration = Preconditions.checkNotNull(configuration, "configuration cannot be null"); client = configuration.newClient(); target = client.target(configuration.getApiEndpoint()).path(configuration.getApiVersion()); commandApi = new CommandApiImpl(this); clusterApi = new ClusterApiImpl(this); hiveMetadataApi = new HiveMetadataApiImpl(this); dbTapsApi = new DbTapApiImpl(this); reportApi = new ReportApiImpl(this); schedulerApi = new SchedulerApiImpl(this); appApi = new AppApiImpl(this); notebookApi = new NotebookApiImpl(this); // register the deserialization handler for composite command SimpleModule module = new SimpleModule("CommandResponseDeserializerModule", new Version(1, 0, 0, null)); SubCommandsDeserializer ccDeserializer = new SubCommandsDeserializer(); module.addDeserializer(SubCommands.class, ccDeserializer); MAPPER.registerModule(module); }
public static String toJson(Object object) { ObjectMapper mapper = new ObjectMapper(new MyJsonFactory()); SimpleModule module = new SimpleModule("fullcalendar", new Version(1, 0, 0, null)); module.addSerializer(new DateTimeSerializer()); module.addSerializer(new LocalTimeSerializer()); mapper.registerModule(module); mapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL); String json = null; try { json = mapper.writeValueAsString(object); } catch (Exception e) { throw new RuntimeException("Error encoding object: " + object + " into JSON string", e); } return json; }
public CustomJSONProvider() { super(); ObjectMapper mapper = new ObjectMapper(); SimpleModule myModule = new SimpleModule("MyOpenDaylightOFFlowJSONSerializerDeserializerModule", new Version(1, 0, 0, null)); myModule.addSerializer(new OpenDaylightOFFlowJSONSerializer()); // assuming OpenDaylightOFFlowJSONSerializer declares correct class to bind to myModule.addDeserializer(OpenDaylightOFFlow.class, new OpenDaylightOFFlowJSONDeserializer()); myModule.addDeserializer(OpenDaylightOFFlowsWrapper.class, new OpenDaylightOFFlowsWrapperJSONDeserializer()); mapper.registerModule(myModule); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT, true); // mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true); super.setMapper(mapper); }
public CustomJSONProvider() { super(); ObjectMapper mapper = new ObjectMapper(); SimpleModule myModule = new SimpleModule("MyFloodlightOFFlowJSONSerializerDeserializerModule", new Version(1, 0, 0, null)); myModule.addSerializer(new FloodlightOFFlowJSONSerializer()); // assuming FloodlightOFFlowJSONSerializer declares correct class to bind to myModule.addDeserializer(FloodlightOFFlow.class, new FloodlightOFFlowJSONDeserializer()); myModule.addDeserializer(FloodlightOFFlowsWrapper.class, new FloodlightOFFlowsWrapperJSONDeserializer()); mapper.registerModule(myModule); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT, true); // mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true); super.setMapper(mapper); }
@Provides public ObjectMapper getObjectMapper() { // configure objectmapper and provide it SimpleModule module = new SimpleModule("SimpleAbstractTypeResolver", Version.unknownVersion()); module.addAbstractTypeMapping(MutableBlobProperties.class, MutableBlobPropertiesImpl.class); module.addAbstractTypeMapping(MutableContentMetadata.class, BaseMutableContentMetadata.class); module.addAbstractTypeMapping(OrionSpecificFileMetadata.class, OrionSpecificFileMetadataImpl.class); module.addAbstractTypeMapping(Attributes.class, AttributesImpl.class); module.addAbstractTypeMapping(OrionError.class, OrionErrorImpl.class); module.addAbstractTypeMapping(OrionChildMetadata.class, OrionChildMetadataImpl.class); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); mapper.setSerializationInclusion(Inclusion.NON_NULL); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper; }
/** * Add Joda-Time deserializers to a module. */ private static void addJodaDeserializers(final SimpleModule module) { for (final StdDeserializer<?> deserializer : new JodaDeserializers().provide()) { module.addDeserializer((Class) deserializer.getValueClass(), deserializer); } module.addDeserializer(Duration.class, DurationDeserializer.create()); module.addDeserializer(Instant.class, InstantDeserializer.create()); module.addDeserializer(ReadableInstant.class, InstantDeserializer.create()); module.addDeserializer(Interval.class, IntervalDeserializer.create()); module.addDeserializer(LocalDate.class, LocalDateDeserializer.create()); }