List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static Object jsonByteArrayObject(byte[] json, Class clazz) { try {/*from w ww .j av a 2s .c om*/ ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper.readValue(json, clazz); } catch (Exception ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); throw new RuntimeException(ex); } }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
private static byte[] objectToJsonByteArray(Object object) { try {//from w w w . ja va 2s. c om ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.writeValue(baos, object); return baos.toByteArray(); } catch (Exception ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); throw new RuntimeException(ex); } }
From source file:de.bund.bfr.knime.node.editableTable.JSONDataTable.java
/** * Loads a table from the settings given. If any errors occur null is returned. * @param settings the settings to load from * @return the table//ww w .j a v a 2 s .c o m * @since 2.10 */ @JsonIgnore public static JSONDataTable loadFromNodeSettings(final NodeSettingsRO settings) { String tableString = settings.getString(KNIME_DATA_TABLE_CONF, null); if (tableString == null) { return null; } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JSONDataTable table = new JSONDataTable(); ObjectReader reader = mapper.readerForUpdating(table); ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(table.getClass().getClassLoader()); reader.readValue(tableString); return table; } catch (IOException e) { LOGGER.error("Unable to load JSON data table: " + e.getMessage(), e); return null; } finally { Thread.currentThread().setContextClassLoader(oldLoader); } }
From source file:com.infinities.skyport.util.JsonUtil.java
public static ObjectMapper getObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper = objectMapper.setAnnotationIntrospector(jaxbAnnotationPair); // make deserializer use JAXB annotations (only) objectMapper = objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper = objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true); return objectMapper; }
From source file:com.simiacryptus.mindseye.applications.ArtistryUtil.java
/** * To json string./* w w w .ja va 2s. c om*/ * * @param obj the style parameters * @return the string */ public static CharSequence toJson(final Object obj) { String json; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); json = mapper.writeValueAsString(obj); } catch (JsonProcessingException e) { throw new RuntimeException(e); } return json; }
From source file:com.bazaarvoice.jolt.JsonUtilImpl.java
public static void configureStockJoltObjectMapper(ObjectMapper objectMapper) { // All Json maps should be deserialized into LinkedHashMaps. SimpleModule stockModule = new SimpleModule("stockJoltMapping", new Version(1, 0, 0, null, null, null)) .addAbstractTypeMapping(Map.class, LinkedHashMap.class); objectMapper.registerModule(stockModule); // allow the mapper to parse JSON with comments in it objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); }
From source file:org.wso2.emm.agent.utils.CommonUtils.java
/** * Revoke currently enforced policy.//w w w . j a v a 2 s. c o m * @param context - Application context. */ public static void revokePolicy(Context context) throws AndroidAgentException { String payload = Preference.getString(context, Constants.PreferenceFlag.APPLIED_POLICY); PolicyOperationsMapper operationsMapper = new PolicyOperationsMapper(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); PolicyRevokeHandler revokeHandler = new PolicyRevokeHandler(context); try { if (payload != null) { List<org.wso2.emm.agent.beans.Operation> operations = mapper.readValue(payload, mapper.getTypeFactory().constructCollectionType(List.class, org.wso2.emm.agent.beans.Operation.class)); for (org.wso2.emm.agent.beans.Operation op : operations) { op = operationsMapper.getOperation(op); revokeHandler.revokeExistingPolicy(op); } Preference.putString(context, Constants.PreferenceFlag.APPLIED_POLICY, null); } } catch (IOException e) { throw new AndroidAgentException("Error occurred while parsing stream", e); } }
From source file:com.vmware.bdd.cli.commands.CommandsUtils.java
private static ObjectMapper getMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); return mapper; }
From source file:org.apache.batchee.jackson.Jacksons.java
public static ObjectMapper newMapper(final String config) { final ObjectMapper mapper = new ObjectMapper(); if (config != null) { final String deserializationName = DeserializationFeature.class.getSimpleName(); final String serializationName = SerializationFeature.class.getSimpleName(); final String mapperName = MapperFeature.class.getSimpleName(); for (final String conf : config.split(",")) { final String[] parts = conf.split("="); parts[0] = parts[0].trim();//from w ww . j av a 2 s . c o m parts[1] = parts[1].trim(); if (parts[0].startsWith(deserializationName)) { mapper.configure( DeserializationFeature.valueOf(parts[0].substring(deserializationName.length() + 1)), Boolean.parseBoolean(parts[1])); } else if (parts[0].startsWith(serializationName)) { mapper.configure( SerializationFeature.valueOf(parts[0].substring(serializationName.length() + 1)), Boolean.parseBoolean(parts[1])); } else if (parts[0].startsWith(mapperName)) { mapper.configure(MapperFeature.valueOf(parts[0].substring(mapperName.length() + 1)), Boolean.parseBoolean(parts[1])); } else { throw new IllegalArgumentException("Ignored config: " + conf); } } } return mapper; }
From source file:com.amazonaws.services.simpleworkflow.flow.common.WorkflowExecutionUtils.java
public static String printDetails(String details) { Throwable failure = null;//from w ww . ja v a 2s.co m try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL); failure = mapper.readValue(details, Throwable.class); } catch (Exception e) { // eat up any data converter exceptions } if (failure != null) { StringBuilder builder = new StringBuilder(); // Also print callstack StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); failure.printStackTrace(pw); builder.append(sw.toString()); details = builder.toString(); } return details; }