Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.readValue()


    public static Map<String, Object> fromJSON(Reader is){
        try {
            ObjectMapper mapper = new ObjectMapper();

            return mapper.readValue(is,
                    new TypeReference<Map<String, Object>>() {});
        } catch (IOException e) {
            throw Exceptions.runtime(e);
        }
    }
View Full Code Here


    public static Map<String, Object> fromJSON(InputStream is){
        try {
            ObjectMapper mapper = new ObjectMapper();

            return mapper.readValue(is,
                new TypeReference<Map<String, Object>>() {});
        } catch (IOException e) {
            throw Exceptions.runtime(e);
        }
    }
View Full Code Here

    public static Map<String, Object> fromJSON(String content){
        try {
            ObjectMapper mapper = new ObjectMapper();

            return mapper.readValue(content,
                new TypeReference<Map<String, Object>>() {});
        } catch (IOException e) {
            throw Exceptions.runtime(e);
        }
    }
View Full Code Here

        return null;
      }
      if (opts.clustersFile != null) {
        ObjectMapper objectMapper = new ObjectMapper();
        File file = new File(opts.clustersFile);
        clustersData = objectMapper.readValue(file, ClusterData.class);
      }
      List<HostPort> hostAndPorts = clustersData.data.get(opts.cluster);
      if (hostAndPorts == null) {
        System.err.println("Cluster " + opts.cluster +
            " not found in data file " + opts.clustersFile);
View Full Code Here

        ObjectMapper mapper = new ObjectMapper(yamlFactory);
        try {

            T ursusHttpServerConfig =
                    mapper.readValue(open(configurationFile), clazz);

            return validate(ursusHttpServerConfig);
        } catch (IOException e) {
            throw new RuntimeException("Error parsing: " + configurationFile, e);
        }
View Full Code Here

        final ObjectMapper oM = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(deserializationModule)
            .setInjectableValues(new InjectableValues.Std().addValue("_serviceLocator", locator));

        return oM.readValue(data, type);
    }
}
View Full Code Here

    {
        ObjectMapper mapper = new ObjectMapper();
        // must register subtypes
        mapper.registerSubtypes(SubB.class, SubC.class, SubD.class);
        String json = mapper.writeValueAsString(new PropertyBean(new SubC()));
        PropertyBean result = mapper.readValue(json, PropertyBean.class);
        assertSame(SubC.class, result.value.getClass());
    }

    // [JACKSON-748]: also works via modules
    public void testSubtypesViaModule() throws Exception
View Full Code Here

        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        module.registerSubtypes(SubB.class, SubC.class, SubD.class);
        mapper.registerModule(module);
        String json = mapper.writeValueAsString(new PropertyBean(new SubC()));
        PropertyBean result = mapper.readValue(json, PropertyBean.class);
        assertSame(SubC.class, result.value.getClass());
    }
   
    public void testSerialization() throws Exception
    {
View Full Code Here

    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerSubtypes(SubC.class);

        // default name should be unqualified class name
        SuperType bean = mapper.readValue("{\"@type\":\"TestSubtypes$SubC\", \"c\":1}", SuperType.class);
        assertSame(SubC.class, bean.getClass());
        assertEquals(1, ((SubC) bean).c);
    }

    public void testDeserializatioNamed() throws Exception
View Full Code Here

    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerSubtypes(SubB.class);
        mapper.registerSubtypes(new NamedType(SubD.class, "TypeD"));

        SuperType bean = mapper.readValue("{\"@type\":\"TypeB\", \"b\":13}", SuperType.class);
        assertSame(SubB.class, bean.getClass());
        assertEquals(13, ((SubB) bean).b);

        // but we can also explicitly register name too
        bean = mapper.readValue("{\"@type\":\"TypeD\", \"d\":-4}", SuperType.class);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.