private static ObjectMapper createDefaultMapper() { final ObjectMapper result = new ObjectMapper(); result.configure(Feature.INDENT_OUTPUT, true); return result; }
@JsonIgnore public String toJson() throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); } }
private static ObjectMapper createCombinedObjectMapper() { final Pair combinedIntrospector = createJaxbJacksonAnnotationIntrospector(); final ObjectMapper result = new ObjectMapper(); result.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true); result.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); result.setDeserializationConfig(result.getDeserializationConfig().withAnnotationIntrospector(combinedIntrospector)); result.setSerializationConfig(result.getSerializationConfig().withAnnotationIntrospector(combinedIntrospector)); return result; }
public void outputJson(PrintWriter writer) throws LlapStatusCliException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY); mapper.setVisibility(JsonMethod.ALL, Visibility.NON_PRIVATE); try { writer.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(appStatusBuilder)); } catch (IOException e) { LOG.warn("Failed to create JSON", e); throw new LlapStatusCliException(ExitCode.LLAP_JSON_GENERATION_ERROR, "Failed to create JSON", e); } }
objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
public void printJson(final SessionState.LogHelper console) { try { waitForReturnSessionEvent(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); // serialize json based on field annotations only objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() .withSetterVisibility(JsonAutoDetect.Visibility.NONE)); String wmContextJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); console.printInfo(""); console.printInfo(WM_EVENTS_TITLE); console.printInfo(SEPARATOR); console.printInfo(wmContextJson); console.printInfo(SEPARATOR); console.printInfo(""); } catch (Exception e) { LOG.warn("Unable to serialize WMContext to json.", e); } }
private void configurePrettyPrint() { if (this.prettyPrint != null) { this.objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, this.prettyPrint); } }
private void configurePrettyPrint() { if (this.prettyPrint != null) { this.objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, this.prettyPrint); } }
/** * Generate java object from bson. * * @param bsonObj * the bsonObj * @param clazz * the clazz * @return the object */ protected Object generateJavaObjectFromBSON(BSONObject bsonObj, Class clazz) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonParser jsonParser; try { jsonParser = new JsonFactory().createJsonParser(bsonObj.toString()); return mapper.readValue(jsonParser, clazz); } catch (JsonParseException e) { throw new KunderaException( "Error in converting Java Object from BSON Object due to error in JSON parsing. Caused BY:", e); } catch (IOException e) { throw new KunderaException("Error in converting Java Object from BSON Object. Caused BY:", e); } }
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); ArrayList<EtlCounts> countsObjects = mapper.readValue(buffer.toString(), new TypeReference<ArrayList<EtlCounts>>() {
private Jsonable getJsonable(Object entityToTransform) { return writer -> { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); mapper.writeValue(writer, entityToTransform); }; }
@VisibleForTesting protected Jsonable getJsonable(InaccessibleProjectTypeDialogContent content) { return writer -> { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); mapper.writeValue(writer, content); }; }
public YarnRestJobStatusProvider(JobsResourceConfig config) { YarnJobResourceConfig yarnConfig = new YarnJobResourceConfig(config); this.httpClient = new HttpClient(); this.apiEndpoint = String.format("http://%s/ws/v1/cluster/apps", yarnConfig.getYarnResourceManagerEndpoint()); OBJECT_MAPPER.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); }
@Override public Jsonable get() { ConstantsManager constantsManager = ComponentAccessor.getConstantsManager(); return writer -> { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); Collection<String> subTaskIds = constantsManager != null ? constantsManager.getSubTaskIssueTypeObjects().stream().map(it -> it.getId()).collect(Collectors.toList()) : ImmutableList.of(); mapper.writeValue(writer, subTaskIds); }; } }
@VisibleForTesting JsonInstanceSerializer(Class<T> payloadClass, boolean compatibleSerializationMode, boolean failOnUnknownProperties) { this.payloadClass = payloadClass; this.compatibleSerializationMode = compatibleSerializationMode; mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, failOnUnknownProperties); type = mapper.getTypeFactory().constructType(ServiceInstance.class); }
@Override public <T> T parse(byte[] data, Type type) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); JavaType javaType = mapper.constructType(type); try { return mapper.readValue(data, javaType); } catch (IOException e) { throw new ParseException("Unable to parse data.", e); } } }
public OpenStackHeatObjectMapperProvider() { objectMapper = new ObjectMapper(); objectMapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false); objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); objectMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); objectMapper.setDeserializationConfig(objectMapper.getDeserializationConfig().withAnnotationIntrospector(introspector)); objectMapper.setSerializationConfig(objectMapper.getSerializationConfig().withSerializationInclusion(Inclusion.NON_NULL) .withAnnotationIntrospector(introspector)); }
protected void requireCreatedUsersNames() { pageBuilderService.assembler().data().requireData("UserBrowser:createdUsersDisplayNames", writer -> { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); objectMapper.writeValue(writer, getCreatedUsersDisplayNames()); }); }
public static ObjectMapper getOperatorValueSerializer() { ObjectMapper returnVal = new ObjectMapper(); returnVal.setVisibilityChecker(new VC()); returnVal.configure(org.codehaus.jackson.map.SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); returnVal.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, As.WRAPPER_OBJECT); returnVal.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); return returnVal; }