public EurekaJacksonCodec(String versionDeltaKey, String appsHashCodeKey) { this.versionDeltaKey = versionDeltaKey; this.appHashCodeKey = appsHashCodeKey; this.mapper = new ObjectMapper(); this.mapper.setSerializationInclusion(Include.NON_NULL); SimpleModule module = new SimpleModule("eureka1.x", VERSION); module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer()); module.addSerializer(InstanceInfo.class, new InstanceInfoSerializer()); module.addSerializer(Application.class, new ApplicationSerializer()); module.addSerializer(Applications.class, new ApplicationsSerializer(this.versionDeltaKey, this.appHashCodeKey)); module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer()); module.addDeserializer(InstanceInfo.class, new InstanceInfoDeserializer(this.mapper)); module.addDeserializer(Application.class, new ApplicationDeserializer(this.mapper)); module.addDeserializer(Applications.class, new ApplicationsDeserializer(this.mapper, this.versionDeltaKey, this.appHashCodeKey)); this.mapper.registerModule(module); Map<Class<?>, Supplier<ObjectReader>> readers = new HashMap<>(); readers.put(InstanceInfo.class, ()->mapper.reader().forType(InstanceInfo.class).withRootName("instance")); readers.put(Application.class, ()->mapper.reader().forType(Application.class).withRootName("application")); readers.put(Applications.class, ()->mapper.reader().forType(Applications.class).withRootName("applications")); this.objectReaderByClass = readers; Map<Class<?>, ObjectWriter> writers = new HashMap<>(); writers.put(InstanceInfo.class, mapper.writer().forType(InstanceInfo.class).withRootName("instance")); writers.put(Application.class, mapper.writer().forType(Application.class).withRootName("application")); writers.put(Applications.class, mapper.writer().forType(Applications.class).withRootName("applications")); this.objectWriterByClass = writers; }
@SuppressWarnings("unchecked") protected THIS initWriter(ObjectWriter writer) { if (_activeView != null) { writer = writer.withView(_activeView); } if (_rootName != null) { writer = writer.withRootName(_rootName); } // Then features if (_serEnable != null) { writer = writer.withFeatures(_serEnable); } if (_serDisable != null) { writer = writer.withoutFeatures(_serDisable); } _writer = writer; return (THIS) this; }
@GET @Path("/companies/all") public Response getAllCompanies() throws JsonProcessingException { List<Company> companies = Lists.newArrayList(); Company yc = new Company(); yc.id = "01"; yc.name = "Yammer Corp"; yc.address = "1 Finite Loop"; companies.add(yc); Company dw = new Company(); dw.id = "02"; dw.name = "DrowWizards Inc"; dw.address = "4 Magic Square, Olympus"; companies.add(dw); ObjectMapper objectMapper = new ObjectMapper(); ObjectWriter writer = objectMapper.writer(); String entity = writer.withRootName("Companies").writeValueAsString(companies); return Response.ok(entity).build(); }
final String request = HaierSupplier.xmlMapper .writer() .withRootName("request") .writeValueAsString(result);
public String build() { ObjectWriter writer = WRITER; if (prettyPrint) { writer = writer.withDefaultPrettyPrinter(); } if (root != null) { writer = writer .with(SerializationFeature.WRAP_ROOT_VALUE) .withRootName(root); } return asJsonString(writer, map); }
public EurekaJacksonCodec(String versionDeltaKey, String appsHashCodeKey) { this.versionDeltaKey = versionDeltaKey; this.appHashCodeKey = appsHashCodeKey; this.mapper = new ObjectMapper(); this.mapper.setSerializationInclusion(Include.NON_NULL); SimpleModule module = new SimpleModule("eureka1.x", VERSION); module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer()); module.addSerializer(InstanceInfo.class, new InstanceInfoSerializer()); module.addSerializer(Application.class, new ApplicationSerializer()); module.addSerializer(Applications.class, new ApplicationsSerializer(this.versionDeltaKey, this.appHashCodeKey)); module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer()); module.addDeserializer(InstanceInfo.class, new InstanceInfoDeserializer(this.mapper)); module.addDeserializer(Application.class, new ApplicationDeserializer(this.mapper)); module.addDeserializer(Applications.class, new ApplicationsDeserializer(this.mapper, this.versionDeltaKey, this.appHashCodeKey)); this.mapper.registerModule(module); Map<Class<?>, Supplier<ObjectReader>> readers = new HashMap<>(); readers.put(InstanceInfo.class, ()->mapper.reader().forType(InstanceInfo.class).withRootName("instance")); readers.put(Application.class, ()->mapper.reader().forType(Application.class).withRootName("application")); readers.put(Applications.class, ()->mapper.reader().forType(Applications.class).withRootName("applications")); this.objectReaderByClass = readers; Map<Class<?>, ObjectWriter> writers = new HashMap<>(); writers.put(InstanceInfo.class, mapper.writer().forType(InstanceInfo.class).withRootName("instance")); writers.put(Application.class, mapper.writer().forType(Application.class).withRootName("application")); writers.put(Applications.class, mapper.writer().forType(Applications.class).withRootName("applications")); this.objectWriterByClass = writers; }
private String createInputJson(String yang, String moduleName) throws MDSALStoreException { StoreYangInputBuilder builder = new StoreYangInputBuilder(); builder.setYang(yang).setModuleName(moduleName); StoreYangInput input = builder.build(); try { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixInAnnotations(StoreYangInput.class, MixIn.class); String inputJson = objectMapper.writer().withRootName("input").writeValueAsString(input); logger.debug("Input JSON :" + inputJson); return inputJson; } catch (JsonProcessingException e) { logger.error(String.format("Error creating JSON input using yang: %s. Error message: %s",yang ,e.getMessage())); throw new MDSALStoreException(String.format("Error creating JSON input using yang: %s. Error message: %s",yang ,e.getMessage()), e); } }
@SuppressWarnings("unchecked") protected THIS initWriter(ObjectWriter writer) { if (_activeView != null) { writer = writer.withView(_activeView); } if (_rootName != null) { writer = writer.withRootName(_rootName); } // Then features if (_serEnable != null) { writer = writer.withFeatures(_serEnable); } if (_serDisable != null) { writer = writer.withoutFeatures(_serDisable); } _writer = writer; return (THIS) this; }
@SuppressWarnings("unchecked") protected THIS initWriter(ObjectWriter writer) { if (_activeView != null) { writer = writer.withView(_activeView); } if (_rootName != null) { writer = writer.withRootName(_rootName); } // Then features if (_serEnable != null) { writer = writer.withFeatures(_serEnable); } if (_serDisable != null) { writer = writer.withoutFeatures(_serDisable); } _writer = writer; return (THIS) this; }
@SuppressWarnings("unchecked") protected THIS initWriter(ObjectWriter writer) { if (_activeView != null) { writer = writer.withView(_activeView); } if (_rootName != null) { writer = writer.withRootName(_rootName); } // Then features if (_serEnable != null) { writer = writer.withFeatures(_serEnable); } if (_serDisable != null) { writer = writer.withoutFeatures(_serDisable); } _writer = writer; return (THIS) this; }
@SuppressWarnings("unchecked") protected THIS initWriter(ObjectWriter writer) { if (_activeView != null) { writer = writer.withView(_activeView); } if (_rootName != null) { writer = writer.withRootName(_rootName); } // Then features if (_serEnable != null) { writer = writer.withFeatures(_serEnable); } if (_serDisable != null) { writer = writer.withoutFeatures(_serDisable); } _writer = writer; return (THIS) this; }
@SuppressWarnings("unchecked") protected THIS initWriter(ObjectWriter writer) { if (_activeView != null) { writer = writer.withView(_activeView); } if (_rootName != null) { writer = writer.withRootName(_rootName); } // Then features if (_serEnable != null) { writer = writer.withFeatures(_serEnable); } if (_serDisable != null) { writer = writer.withoutFeatures(_serDisable); } _writer = writer; return (THIS) this; }
.withRootName("instance")); writers.put(Application.class, mapper.writer().withType(Application.class) .withRootName("application")); writers.put(Applications.class, mapper.writer().withType(Applications.class) .withRootName("applications")); setField("objectWriterByClass", writers);
.withRootName("instance")); writers.put(Application.class, mapper.writer().withType(Application.class) .withRootName("application")); writers.put(Applications.class, mapper.writer().withType(Applications.class) .withRootName("applications")); setField("objectWriterByClass", writers);
(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true).writer().withRootName("vnfcs"); try { dependencyJson = writer.writeValueAsString(vnfcs);