当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.readValue方法代码示例

本文整理汇总了Java中org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper.readValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.readValue方法的具体用法?Java ObjectMapper.readValue怎么用?Java ObjectMapper.readValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.readValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldSerializeTraversalMetrics

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Ignore
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final TraversalMetrics tm = (TraversalMetrics) g.V().both().profile().next();
    final String json = mapper.writeValueAsString(tm);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertTrue(m.containsKey(GraphSONTokens.DURATION));
    assertTrue(m.containsKey(GraphSONTokens.METRICS));

    final List<Map<String, Object>> metrics = (List<Map<String, Object>>) m.get(GraphSONTokens.METRICS);
    assertEquals(2, metrics.size());

    final Map<String, Object> metrics0 = metrics.get(0);
    assertTrue(metrics0.containsKey(GraphSONTokens.ID));
    assertTrue(metrics0.containsKey(GraphSONTokens.NAME));
    assertTrue(metrics0.containsKey(GraphSONTokens.COUNTS));
    assertTrue(metrics0.containsKey(GraphSONTokens.DURATION));
}
 
开发者ID:rayokota,项目名称:hgraphdb,代码行数:22,代码来源:CustomTest.java

示例2: shouldSerializeVertex

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final Vertex v = graph.vertices(convertToVertexId("marko")).next();
    final String json = mapper.writeValueAsString(v);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(GraphSONTokens.VERTEX, m.get(GraphSONTokens.TYPE));
    assertEquals(v.label(), m.get(GraphSONTokens.LABEL));
    assertNotNull(m.get(GraphSONTokens.ID));
    final Map<String,List<Map<String,Object>>> properties = (Map<String,List<Map<String,Object>>>) m.get(GraphSONTokens.PROPERTIES);
    assertEquals(v.value("name").toString(), properties.get("name").get(0).get(GraphSONTokens.VALUE).toString());
    assertEquals((Integer) v.value("age"), properties.get("age").get(0).get(GraphSONTokens.VALUE));
    assertEquals(1, properties.get("name").size());
    assertEquals(1, properties.get("age").size());
    assertEquals(2, properties.size());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:SerializationTest.java

示例3: shouldSerializeTraversalMetrics

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final TraversalMetrics tm = (TraversalMetrics) g.V().both().profile().next();
    final String json = mapper.writeValueAsString(tm);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertTrue(m.containsKey(GraphSONTokens.DURATION));
    assertTrue(m.containsKey(GraphSONTokens.METRICS));

    final List<Map<String, Object>> metrics = (List<Map<String, Object>>) m.get(GraphSONTokens.METRICS);
    assertEquals(2, metrics.size());

    final Map<String, Object> metrics0 = metrics.get(0);
    assertTrue(metrics0.containsKey(GraphSONTokens.ID));
    assertTrue(metrics0.containsKey(GraphSONTokens.NAME));
    assertTrue(metrics0.containsKey(GraphSONTokens.COUNTS));
    assertTrue(metrics0.containsKey(GraphSONTokens.DURATION));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:SerializationTest.java

示例4: shouldSerializeTraversalMetrics

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final TraversalMetrics before = g.V().both().profile().next();
    final String json = mapper.writeValueAsString(before);
    final TraversalMetrics after = mapper.readValue(json, TraversalMetrics.class);

    assertNotNull(after);
    assertEquals(before.getMetrics().size(), after.getMetrics().size());
    assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS));
    assertEquals(before.getMetrics().size(), after.getMetrics().size());

    before.getMetrics().forEach(b -> {
        final Optional<? extends Metrics> mFromA = after.getMetrics().stream().filter(a -> b.getId().equals(a.getId())).findFirst();
        if (mFromA.isPresent()) {
            final Metrics m = mFromA.get();
            assertEquals(b.getAnnotations(), m.getAnnotations());
            assertEquals(b.getCounts(), m.getCounts());
            assertEquals(b.getName(), m.getName());
            assertEquals(b.getDuration(TimeUnit.MILLISECONDS), m.getDuration(TimeUnit.MILLISECONDS));
        } else {
            fail("Metrics were not present after deserialization");
        }
    });
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:27,代码来源:SerializationTest.java

示例5: shouldHandleMapWithTypesUsingEmbedTypeSettingV2d0

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void shouldHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
    final ObjectMapper mapper = GraphSONMapper.build()
            .version(GraphSONVersion.V2_0)
            .typeInfo(TypeInfo.PARTIAL_TYPES)
            .create()
            .createMapper();

    final Map<String,Object> m = new HashMap<>();
    m.put("test", 100L);

    final String json = mapper.writeValueAsString(m);
    final Map read = mapper.readValue(json, HashMap.class);

    assertEquals(100L, read.get("test"));
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:17,代码来源:GraphSONMapperPartialEmbeddedTypeTest.java

示例6: shouldHandleMapWithTypesUsingEmbedTypeSettingV1d0

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void shouldHandleMapWithTypesUsingEmbedTypeSettingV1d0() throws Exception {
    final ObjectMapper mapper = GraphSONMapper.build()
            .version(GraphSONVersion.V1_0)
            .typeInfo(TypeInfo.PARTIAL_TYPES)
            .create()
            .createMapper();

    final Map<String,Object> m = new HashMap<>();
    m.put("test", 100L);

    final String json = mapper.writeValueAsString(m);
    final Map read = mapper.readValue(json, HashMap.class);

    assertEquals(100L, read.get("test"));
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:17,代码来源:GraphSONMapperPartialEmbeddedTypeTest.java

示例7: shouldSerializeVertexPropertyWithProperties

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldSerializeVertexPropertyWithProperties() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next();
    final String json = mapper.writeValueAsString(vp);
    final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class);

    assertNotNull(detached);
    assertEquals(vp.label(), detached.label());
    assertEquals(vp.id(), detached.id());
    assertEquals(vp.value(), detached.value());
    assertEquals(vp.values("startTime").next(), detached.values("startTime").next());
    assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key());
    assertEquals(vp.values("endTime").next(), detached.values("endTime").next());
    assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key());
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:18,代码来源:SerializationTest.java

示例8: shouldSerializeEdge

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
    final String json = mapper.writeValueAsString(e);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(GraphSONTokens.EDGE, m.get(GraphSONTokens.TYPE));
    assertEquals(e.label(), m.get(GraphSONTokens.LABEL));
    assertNotNull(m.get(GraphSONTokens.ID));
    assertEquals((Double) e.value("weight"), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("weight"));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:14,代码来源:SerializationTest.java

示例9: shouldSerializeProperty

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
    final String json = mapper.writeValueAsString(p);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(p.value(), m.get(GraphSONTokens.VALUE));
    assertEquals(p.key(), m.get(GraphSONTokens.KEY));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:12,代码来源:SerializationTest.java

示例10: shouldSerializeVertexProperty

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
    final String json = mapper.writeValueAsString(vp);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(vp.label(), m.get(GraphSONTokens.LABEL));
    assertNotNull(m.get(GraphSONTokens.ID));
    assertEquals(vp.value(), m.get(GraphSONTokens.VALUE));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:13,代码来源:SerializationTest.java

示例11: shouldSerializeVertexPropertyWithProperties

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldSerializeVertexPropertyWithProperties() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next();
    final String json = mapper.writeValueAsString(vp);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(vp.label(), m.get(GraphSONTokens.LABEL));
    assertNotNull(m.get(GraphSONTokens.ID));
    assertEquals(vp.value(), m.get(GraphSONTokens.VALUE));
    assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime"));
    assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime"));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:15,代码来源:SerializationTest.java

示例12: shouldSerializeProperty

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
    final String json = mapper.writeValueAsString(p);
    final Property detached = mapper.readValue(json, Property.class);

    assertNotNull(detached);
    assertEquals(p.key(), detached.key());
    assertEquals(p.value(), detached.value());
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:13,代码来源:SerializationTest.java

示例13: shouldSerializeEdge

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
    final String json = mapper.writeValueAsString(e);
    final Edge detached = mapper.readValue(json, Edge.class);

    assertNotNull(detached);
    assertEquals(e.label(), detached.label());
    assertEquals(e.id(), detached.id());
    assertEquals((Double) e.value("weight"), detached.value("weight"));
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:14,代码来源:SerializationTest.java

示例14: serializeDeserialize

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static <T> T serializeDeserialize(final ObjectMapper mapper, final Object o, final Class<T> clazz) throws Exception {
    try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
        mapper.writeValue(stream, o);
        try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray())) {
            return mapper.readValue(inputStream, clazz);
        }
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:9,代码来源:AbstractGraphSONTest.java

示例15: serializeDeserializeAuto

import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static <T> T serializeDeserializeAuto(final ObjectMapper mapper, final Object o) throws Exception {
    try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
        mapper.writeValue(stream, o);

        try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray())) {
            // Object.class is the wildcard that triggers the auto discovery.
            return (T)mapper.readValue(inputStream, Object.class);
        }
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:11,代码来源:AbstractGraphSONTest.java


注:本文中的org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper.readValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。