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

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

Introduction

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

Prototype

public ObjectMapper() 

Source Link

Document

Default constructor, which will construct the default JsonFactory as necessary, use SerializerProvider as its SerializerProvider , and BeanSerializerFactory as its SerializerFactory .

Usage

From source file:cf.client.Token.java

public static Token parseJson(InputStream json) {
    try {//w w  w  .j a  va  2s  .c  om
        final JsonNode node = new ObjectMapper().readTree(json);
        final String accessToken = node.get("access_token").asText();
        final Type type = Type.getType(node.get("token_type").asText());
        final Date expiration = new Date(System.currentTimeMillis() + node.get("expires_in").asLong());
        final String rawScopes = node.get("scope").asText();
        final String[] splitScopes = rawScopes.split("\\s+");
        final List<String> scopes = Collections.unmodifiableList(Arrays.asList(splitScopes));
        final UUID jti = UUID.fromString(node.get("jti").asText());
        return new Token(accessToken, type, expiration, scopes, jti);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.assoba.open.sel.generator.JSONGenerator.java

@Override
public void generate(List<Namespace> namespaces, IO io) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    for (Namespace namespace : namespaces) {
        String output = mapper.writeValueAsString(namespace);
        io.writeFile(namespace.getName() + ".json", output);
    }//from   ww w.  j a v  a 2  s  .  com
}

From source file:com.flipkart.flux.api.WorkflowStateSummaryTest.java

@Before
public void setUp() throws Exception {
    objectMapper = new ObjectMapper();
    stateSummary = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("state_summary.json"));
}

From source file:com.helpmobile.test.Booking.java

@Test
public void book() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    RestAccess restAccess = new RestAccess();
    String back = restAccess.doPostRequest("workshop/booking/create", null, "POST");
}

From source file:br.com.catbag.gifreduxsample.models.Gif.java

public static Gif fromJson(String json) throws IOException {
    return new ObjectMapper().readValue(json, Gif.class);
}

From source file:com.josue.jboss.custom.jackson.provider.CustomJacksonProvider.java

public CustomJacksonProvider() {
    LOG.info("********  CUSTOMJACKSONPROVIDER  ***********");
    mapper = new ObjectMapper();
    mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"));
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

From source file:de.dfki.asr.compass.rest.providers.JacksonContextResolver.java

/**
 * Creates a new instance./*from  ww w .j  ava  2s . c o  m*/
 */
public JacksonContextResolver() {
    this.objectMapper = new ObjectMapper();
    this.objectMapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    this.objectMapper.findAndRegisterModules();
}

From source file:io.fouad.jtb.core.utils.JsonUtils.java

public static <T, R> T toJavaObject(String json, TypeReference typeReference) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
    return mapper.readValue(json, typeReference);
}

From source file:com.flipkart.flux.api.WorkflowStatesDetailTest.java

@Before
public void setUp() throws Exception {
    objectMapper = new ObjectMapper();
    statesDetail = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("states_detail.json"));
}

From source file:org.mule.modules.rest.model.LeagueTransformers.java

@Transformer(resultMimeType = "application/json")
public String toJson(League league) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(league);
}