Example usage for com.fasterxml.jackson.databind ObjectMapper readValue

List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper readValue.

Prototype

@SuppressWarnings("unchecked")
    public <T> T readValue(byte[] src, JavaType valueType)
            throws IOException, JsonParseException, JsonMappingException 

Source Link

Usage

From source file:io.coala.json.JsonUtil.java

/**
 * @param json the {@link InputStream}//from w ww.  j ava  2  s .c o m
 * @param resultType the type of result {@link Object}
 * @return the parsed/deserialized/unmarshalled {@link Object}
 */
public static <T> T valueOf(final InputStream json, final Class<T> resultType, final Properties... imports) {
    if (json == null)
        return null;
    try {
        final ObjectMapper om = getJOM();
        return (T) om.readValue(json, checkRegistered(om, resultType, imports));
    } catch (final Exception e) {
        return Thrower.rethrowUnchecked(e);
    }
}

From source file:com.company.et.service.JsonService.java

public static Professor jsonToObjectProfessor(String json) throws IOException, ParseException {

    ObjectMapper mapper = new ObjectMapper();

    SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null))
            .addDeserializer(Professor.class, new ProfessorDeserializer());

    mapper.registerModule(testModule);/*ww w .  j ava2 s  . com*/

    Professor obj = mapper.readValue(json, Professor.class);

    return obj;
}

From source file:org.apache.usergrid.chop.api.store.amazon.EC2InstanceManagerTest.java

@BeforeClass
public static void setUpData() {
    Injector injector = Guice.createInjector(new AmazonModule());
    amazonFig = injector.getInstance(AmazonFig.class);

    String accessKey = amazonFig.getAwsAccessKey();
    String secretKey = amazonFig.getAwsSecretKey();

    if (accessKey == null || accessKey.equals("${aws.access.key}") || accessKey.isEmpty() || secretKey == null
            || secretKey.equals("${aws.secret.key}") || secretKey.isEmpty()) {

        LOG.warn("EC2InstanceManagerTest tests are not run, "
                + "Provided AWS secret or access key values are invalid or no values are provided");
    } else {/*from ww w.  ja va2s  .c  o m*/
        try {
            ObjectMapper mapper = new ObjectMapper();
            InputStream is = EC2InstanceManagerTest.class.getClassLoader()
                    .getResourceAsStream("test-stack.json");
            Stack basicStack = mapper.readValue(is, Stack.class);

            /** Commit mock object get method values */
            when(commit.getCreateTime()).thenReturn(new Date());
            when(commit.getMd5()).thenReturn("742e2a76a6ba161f9efb87ce58a9187e");
            when(commit.getModuleId()).thenReturn("2000562494");
            when(commit.getRunnerPath()).thenReturn("/some/dummy/path");
            when(commit.getId()).thenReturn("cc471b502aca2791c3a068f93d15b79ff6b7b827");

            /** Module mock object get method values */
            when(module.getGroupId()).thenReturn("org.apache.usergrid.chop");
            when(module.getArtifactId()).thenReturn("chop-maven-plugin");
            when(module.getVersion()).thenReturn("1.0-SNAPSHOT");
            when(module.getVcsRepoUrl()).thenReturn("https://stash.safehaus.org/scm/chop/main.git");
            when(module.getTestPackageBase()).thenReturn("org.apache.usergrid.chop");
            when(module.getId()).thenReturn("2000562494");

            stack = new CoordinatedStack(basicStack, new User("user", "pass"), commit, module, RUNNER_COUNT);
        } catch (Exception e) {
            LOG.error("Error while reading test stack json resource", e);
            return;
        }

        manager = injector.getInstance(EC2InstanceManager.class);
    }
}

From source file:com.msopentech.odatajclient.engine.data.Deserializer.java

private static JSONFeed toJSONFeed(final InputStream input) {
    try {//from  w  w  w . j  a  va 2  s .  c  o m
        final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.readValue(input, JSONFeed.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("While deserializing JSON feed", e);
    }
}

From source file:com.msopentech.odatajclient.engine.data.Deserializer.java

private static JSONEntry toJSONEntry(final InputStream input) {
    try {/*from  www.j a  v  a 2 s . co m*/
        final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.readValue(input, JSONEntry.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("While deserializing JSON entry", e);
    }
}

From source file:com.msopentech.odatajclient.engine.data.Deserializer.java

private static Element toPropertyDOMFromJSON(final InputStream input) {
    try {//from w ww. j av  a  2  s . co m
        final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.readValue(input, JSONProperty.class).getContent();
    } catch (IOException e) {
        throw new IllegalArgumentException("While deserializing JSON property", e);
    }
}

From source file:com.msopentech.odatajclient.engine.data.Deserializer.java

private static ServiceDocumentResource toServiceDocumentFromJSON(final InputStream input) {
    try {/*from   w  ww  .  j  a  va2 s .  com*/
        final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.readValue(input, JSONServiceDocument.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("While deserializing JSON service document", e);
    }
}

From source file:com.msopentech.odatajclient.engine.data.Deserializer.java

private static JSONLinkCollection toLinkCollectionFromJSON(final InputStream input) {
    try {/*  w  w w.  j  a  va2  s . c o m*/
        final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.readValue(input, JSONLinkCollection.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("While deserializing JSON $links", e);
    }
}

From source file:com.msopentech.odatajclient.engine.data.Deserializer.java

private static JSONODataError toODataErrorFromJSON(final InputStream input) {
    try {//from   w  w w.  j a  v a2s.com
        final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

        return mapper.readValue(input, JSONODataErrorBundle.class).getError();
    } catch (IOException e) {
        throw new IllegalArgumentException("While deserializing JSON error", e);
    }
}

From source file:org.entcore.common.user.UserUtils.java

public static UserInfos sessionToUserInfos(JsonObject session) {
    if (session == null) {
        return null;
    }// w ww .ja  v  a  2s.c  om
    ObjectMapper mapper = new ObjectMapper();
    try {
        return mapper.readValue(session.encode(), UserInfos.class);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}