List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper
public ObjectMapper()
From source file:org.obiba.mica.config.JsonConfiguration.java
@Bean public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.findAndRegisterModules();/*from w w w .j a va2s .c o m*/ return mapper; }
From source file:com.hp.autonomy.iod.client.error.IodErrorTest.java
@Test public void testFromJson() throws IOException { final InputStream jsonStream = getClass() .getResourceAsStream("/com/hp/autonomy/iod/client/error/error.json"); final ObjectMapper mapper = new ObjectMapper(); final IodError error = mapper.readValue(jsonStream, IodError.class); assertThat(error.getErrorCode(), is(IodErrorCode.MISSING_REQUIRED_PARAMETERS)); }
From source file:io.klerch.alexa.tellask.util.factory.AlexaSpeechletFactory.java
/** * Creates an AlexaSpeechlet from bytes of a speechlet request. It will extract the * locale from the request and uses it for creating a new instance of AlexaSpeechlet * @param serializedSpeechletRequest bytes of a speechlet request * @param speechletClass the class of your AlexaSpeechlet to instantiate * @param utteranceReader the reader AlexaSpeechlet should use when reading out utterances * @param <T> must extend AlexaSpeechlet * @return new instance of AlexaSpeechlet * @throws IOException thrown when something went wrong */// w w w .j a v a 2 s .c o m public static <T extends AlexaSpeechlet> T createSpeechletFromRequest(final byte[] serializedSpeechletRequest, final Class<T> speechletClass, final UtteranceReader utteranceReader) throws IOException { final ObjectMapper mapper = new ObjectMapper(); final JsonNode parser = mapper.readTree(serializedSpeechletRequest); final String locale = Optional.of(parser.path("request")).filter(node -> !node.isMissingNode()) .map(node -> node.path("locale")).filter(node -> !node.isMissingNode()).map(JsonNode::textValue) .orElse(DEFAULT_LOCALE); try { return speechletClass.getConstructor(String.class, UtteranceReader.class).newInstance(locale, utteranceReader); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IOException("Could not create Speechlet from speechlet request", e); } }
From source file:nl.knaw.huygens.alexandria.concordion.JsonConfiguration.java
private static ObjectMapper createDefaultMapper() { final ObjectMapper mapper = new ObjectMapper(); Log.debug("Configuring Jackson ObjectMapper: [" + mapper + "]"); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // mapper.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); return mapper; }
From source file:org.opendaylight.sfc.sbrest.json.AbstractExporter.java
AbstractExporter() { this.mapper = new ObjectMapper(); this.mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); }
From source file:com.hp.autonomy.hod.client.error.HodErrorTest.java
@Test public void testFromJson() throws IOException { final InputStream jsonStream = getClass() .getResourceAsStream("/com/hp/autonomy/hod/client/error/error.json"); final ObjectMapper mapper = new ObjectMapper(); final HodError error = mapper.readValue(jsonStream, HodError.class); assertThat(error.getErrorCode(), is(HodErrorCode.MISSING_REQUIRED_PARAMETERS)); }
From source file:de.kaojo.chat.TextMessageDecoder.java
@Override public Message decode(String s) throws DecodeException { ObjectMapper mapper = new ObjectMapper(); try {//from w w w . j a v a 2s. co m return mapper.readValue(s, Message.class); } catch (IOException ex) { Logger.getLogger(TextMessageDecoder.class.getName()).log(Level.SEVERE, null, ex); throw new DecodeException(s, "Encoded message could not be parsed to Message.class"); } }
From source file:com.proofpoint.json.testing.JsonTester.java
public static <T> void assertJsonEncode(T pojo, Object expected, String message) { try {/*from w w w . j a va 2 s . c om*/ String json = new ObjectMapperProvider().get().enable(INDENT_OUTPUT).writeValueAsString(pojo); StringBuilder builder = new StringBuilder(); if (message != null) { builder.append(message).append(' '); } builder.append("JSON encoding ").append(json); assertEquals(new ObjectMapper().readValue(json, Object.class), expected, builder.toString()); } catch (IOException e) { throw propagate(e); } }
From source file:com.codemacro.jcm.util.JsonUtil.java
public static <T> T fromString(String str, TypeReference<T> tref) throws IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(str, tref); }
From source file:org.hdl.tensorflow.yarn.appmaster.ClusterSpec.java
public static ClusterSpec fromJsonString(String json) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); return new ClusterSpec(objectMapper.readValue(json, Map.class)); }