List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
From source file:com.csc.fi.ioapi.utils.LDHelper.java
private static Map<String, Object> jsonObject(String json) { try {/*www .ja v a2s . co m*/ ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); return mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { }); } catch (IOException ex) { System.out.println(ex.toString()); return null; } }
From source file:com.github.srgg.yads.JsonUnitInitializer.java
public static ObjectMapper initialize() { // making JsonAssert to be more tolerant to JSON format final Object converter; try {/*from www .j a v a2s .c o m*/ converter = FieldUtils.readStaticField(JsonUtils.class, "converter", true); final List<NodeFactory> factories = (List<NodeFactory>) FieldUtils.readField(converter, "factories", true); ObjectMapper mapper; for (NodeFactory nf : factories) { if (nf.getClass().getSimpleName().equals("Jackson2NodeFactory")) { mapper = (ObjectMapper) FieldUtils.readField(nf, "mapper", true); mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true) .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); return mapper; } } } catch (IllegalAccessException e) { throw new IllegalStateException("Can't initialize Jackson2 ObjectMapper because of UE", e); } throw new IllegalStateException("Can't initialize Jackson2 ObjectMapper, Jackson2NodeFactory is not found"); }
From source file:ch.rasc.extclassgenerator.ModelAnnotationProcessor.java
private static String generateSubclassCode(Class<?> clazz, OutputConfig outputConfig) { Model modelAnnotation = clazz.getAnnotation(Model.class); String name;/*from ww w .ja v a 2 s.c o m*/ if (modelAnnotation != null && StringUtils.hasText(modelAnnotation.value())) { name = modelAnnotation.value(); } else { name = clazz.getName(); } Map<String, Object> modelObject = new LinkedHashMap<String, Object>(); modelObject.put("extend", name + "Base"); StringBuilder sb = new StringBuilder(100); sb.append("Ext.define(\"").append(name).append("\","); if (outputConfig.isDebug()) { sb.append("\n"); } String configObjectString; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false); if (!outputConfig.isSurroundApiWithQuotes()) { if (outputConfig.getOutputFormat() == OutputFormat.EXTJS5) { mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithoutApiQuotesExtJs5Mixin.class); } else { mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithoutApiQuotesMixin.class); } mapper.addMixInAnnotations(ApiObject.class, ApiObjectMixin.class); } else { if (outputConfig.getOutputFormat() != OutputFormat.EXTJS5) { mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithApiQuotesMixin.class); } } if (outputConfig.isDebug()) { configObjectString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(modelObject); } else { configObjectString = mapper.writeValueAsString(modelObject); } } catch (JsonGenerationException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } sb.append(configObjectString); sb.append(");"); if (outputConfig.isUseSingleQuotes()) { return sb.toString().replace('"', '\''); } return sb.toString(); }
From source file:net.roboconf.dm.rest.commons.json.JSonBindingUtils.java
/** * Creates a mapper with specific binding for Roboconf types. * @return a non-null, configured mapper *//*from www . ja va 2 s .co m*/ public static ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); SimpleModule module = new SimpleModule("RoboconfModule", new Version(1, 0, 0, null, null, null)); module.addSerializer(Instance.class, new InstanceSerializer()); module.addDeserializer(Instance.class, new InstanceDeserializer()); module.addSerializer(Application.class, new ApplicationSerializer()); module.addDeserializer(Application.class, new ApplicationDeserializer()); module.addSerializer(Component.class, new ComponentSerializer()); module.addDeserializer(Component.class, new ComponentDeserializer()); mapper.registerModule(module); return mapper; }
From source file:de.adorsys.multibanking.hbci.job.ScaRequiredJob.java
private static ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.findAndRegisterModules(); return objectMapper; }
From source file:org.nohope.jongo.JacksonProcessor.java
@Nonnull private static ObjectMapper createPreConfiguredMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); mapper.registerModule(new ColorModule()); mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(AUTO_DETECT_GETTERS, false); mapper.configure(AUTO_DETECT_SETTERS, false); mapper.setSerializationInclusion(NON_NULL); mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY)); mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.Id.CLASS.getDefaultPropertyName()); final SimpleModule module = new SimpleModule("jongo", Version.unknownVersion()); module.addKeySerializer(Object.class, ComplexKeySerializer.S_OBJECT); module.addKeyDeserializer(String.class, ComplexKeyDeserializer.S_OBJECT); module.addKeyDeserializer(Object.class, ComplexKeyDeserializer.S_OBJECT); //addBSONTypeSerializers(module); mapper.registerModule(module);//from w ww . j a v a 2 s .c om return mapper; }
From source file:keywhiz.KeywhizService.java
/** * Customizes ObjectMapper for common settings. * * @param objectMapper to be customized//from w ww . j a v a2 s . co m * @return customized input factory */ public static ObjectMapper customizeObjectMapper(ObjectMapper objectMapper) { objectMapper.registerModules(new Jdk8Module()); objectMapper.registerModules(new JavaTimeModule()); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
From source file:com.arpnetworking.jackson.ObjectMapperFactory.java
private static ObjectMapper createModifiableObjectMapper(final String name) { final ObjectMapper objectMapper = new ObjectMapper(); final SimpleModule module = new SimpleModule(name); module.addSerializer(Optional.class, OptionalSerializer.newInstance()); objectMapper.registerModule(module); objectMapper.registerModule(new JodaModule()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.WRAP_EXCEPTIONS, false); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); return objectMapper; }
From source file:svnserver.ext.web.server.WebServer.java
@NotNull public static ObjectMapper createJsonMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper; }
From source file:com.jaspersoft.studio.community.RESTCommunityHelper.java
/** * Tries to retrieve the content for the specified node ID. * /*from w ww . jav a 2s . c o m*/ * @param httpclient * the http client * @param nodeID * the node ID * @param authCookie * the session cookie to use for authentication purpose * @return the node content as JSON * @throws CommunityAPIException */ public static JsonNode retrieveNodeContentAsJSON(CloseableHttpClient httpclient, String nodeID, Cookie authCookie) throws CommunityAPIException { try { HttpGet retrieveNodeContentGET = new HttpGet( CommunityConstants.NODE_CONTENT_URL_PREFIX + nodeID + ".json"); //$NON-NLS-1$ CloseableHttpResponse resp = httpclient.execute(retrieveNodeContentGET); int httpRetCode = resp.getStatusLine().getStatusCode(); String responseBodyAsString = EntityUtils.toString(resp.getEntity()); if (HttpStatus.SC_OK == httpRetCode) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); JsonNode jsonRoot = mapper.readTree(responseBodyAsString); return jsonRoot; } else { CommunityAPIException ex = new CommunityAPIException( Messages.RESTCommunityHelper_NodeContentRetrieveError); ex.setHttpStatusCode(httpRetCode); ex.setResponseBodyAsString(responseBodyAsString); throw ex; } } catch (IOException e) { JSSCommunityActivator.getDefault().logError(Messages.RESTCommunityHelper_GetMethodIOError, e); throw new CommunityAPIException(Messages.RESTCommunityHelper_NodeContentRetrieveError, e); } }