Java Code Examples for org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeObject()
The following examples show how to use
org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphSONSerializersV2d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void serialize(final Metrics metrics, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.ID, metrics.getId()); m.put(GraphSONTokens.NAME, metrics.getName()); m.put(GraphSONTokens.COUNTS, metrics.getCounts()); m.put(GraphSONTokens.DURATION, metrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d); if (!metrics.getAnnotations().isEmpty()) { m.put(GraphSONTokens.ANNOTATIONS, metrics.getAnnotations()); } if (!metrics.getNested().isEmpty()) { final List<Metrics> nested = new ArrayList<>(); metrics.getNested().forEach(it -> nested.add(it)); m.put(GraphSONTokens.METRICS, nested); } jsonGenerator.writeObject(m); }
Example 2
Source File: GraphSONSerializersV2d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void serialize(final TraversalExplanation traversalExplanation, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.ORIGINAL, getStepsAsList(traversalExplanation.getOriginalTraversal())); final List<Pair<TraversalStrategy, Traversal.Admin<?, ?>>> strategyTraversals = traversalExplanation.getStrategyTraversals(); final List<Map<String, Object>> intermediates = new ArrayList<>(); for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pair : strategyTraversals) { final Map<String, Object> intermediate = new HashMap<>(); intermediate.put(GraphSONTokens.STRATEGY, pair.getValue0().toString()); intermediate.put(GraphSONTokens.CATEGORY, pair.getValue0().getTraversalCategory().getSimpleName()); intermediate.put(GraphSONTokens.TRAVERSAL, getStepsAsList(pair.getValue1())); intermediates.add(intermediate); } m.put(GraphSONTokens.INTERMEDIATE, intermediates); if (strategyTraversals.isEmpty()) m.put(GraphSONTokens.FINAL, getStepsAsList(traversalExplanation.getOriginalTraversal())); else m.put(GraphSONTokens.FINAL, getStepsAsList(strategyTraversals.get(strategyTraversals.size() - 1).getValue1())); jsonGenerator.writeObject(m); }
Example 3
Source File: GraphSONSerializersV3d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void serialize(final TraversalExplanation traversalExplanation, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.ORIGINAL, getStepsAsList(traversalExplanation.getOriginalTraversal())); final List<Pair<TraversalStrategy, Traversal.Admin<?, ?>>> strategyTraversals = traversalExplanation.getStrategyTraversals(); final List<Map<String, Object>> intermediates = new ArrayList<>(); for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pair : strategyTraversals) { final Map<String, Object> intermediate = new HashMap<>(); intermediate.put(GraphSONTokens.STRATEGY, pair.getValue0().toString()); intermediate.put(GraphSONTokens.CATEGORY, pair.getValue0().getTraversalCategory().getSimpleName()); intermediate.put(GraphSONTokens.TRAVERSAL, getStepsAsList(pair.getValue1())); intermediates.add(intermediate); } m.put(GraphSONTokens.INTERMEDIATE, intermediates); if (strategyTraversals.isEmpty()) m.put(GraphSONTokens.FINAL, getStepsAsList(traversalExplanation.getOriginalTraversal())); else m.put(GraphSONTokens.FINAL, getStepsAsList(strategyTraversals.get(strategyTraversals.size() - 1).getValue1())); jsonGenerator.writeObject(m); }
Example 4
Source File: TraversalSerializersV3d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.PREDICATE, p instanceof ConnectiveP ? p instanceof AndP ? GraphSONTokens.AND : GraphSONTokens.OR : p.getBiPredicate().toString()); if (p instanceof ConnectiveP) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) { jsonGenerator.writeObject(predicate); } jsonGenerator.writeEndArray(); } else jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue()); jsonGenerator.writeEndObject(); }
Example 5
Source File: GraphSONSerializersV3d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void serialize(final Metrics metrics, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.ID, metrics.getId()); m.put(GraphSONTokens.NAME, metrics.getName()); m.put(GraphSONTokens.COUNTS, metrics.getCounts()); m.put(GraphSONTokens.DURATION, metrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d); if (!metrics.getAnnotations().isEmpty()) { m.put(GraphSONTokens.ANNOTATIONS, metrics.getAnnotations()); } if (!metrics.getNested().isEmpty()) { final List<Metrics> nested = new ArrayList<>(); metrics.getNested().forEach(it -> nested.add(it)); m.put(GraphSONTokens.METRICS, nested); } jsonGenerator.writeObject(m); }
Example 6
Source File: SchemaTable.java From sqlg with MIT License | 6 votes |
@SuppressWarnings("deprecation") @Override public void serializeWithType(final SchemaTable schemaTable, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException, JsonProcessingException { // when the type is included add "class" as a key and then try to utilize as much of the // default serialization provided by jackson data-bind as possible. for example, write // the uuid as an object so that when jackson serializes it, it uses the uuid serializer // to write it out with the type. in this way, data-bind should be able to deserialize // it back when types are embedded. typeSerializer.writeTypePrefixForScalar(schemaTable, jsonGenerator); final Map<String, Object> m = new LinkedHashMap<>(); m.put("schema", schemaTable.getSchema()); m.put("table", schemaTable.getTable()); jsonGenerator.writeObject(m); typeSerializer.writeTypeSuffixForScalar(schemaTable, jsonGenerator); }
Example 7
Source File: GraphSONSerializersV1d0.java From tinkerpop with Apache License 2.0 | 6 votes |
public void ser(final TraversalExplanation te, final JsonGenerator jsonGenerator) throws IOException { final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.ORIGINAL, getStepsAsList(te.getOriginalTraversal())); final List<Pair<TraversalStrategy, Traversal.Admin<?,?>>> strategyTraversals = te.getStrategyTraversals(); final List<Map<String,Object>> intermediates = new ArrayList<>(); for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pair : strategyTraversals) { final Map<String,Object> intermediate = new HashMap<>(); intermediate.put(GraphSONTokens.STRATEGY, pair.getValue0().toString()); intermediate.put(GraphSONTokens.CATEGORY, pair.getValue0().getTraversalCategory().getSimpleName()); intermediate.put(GraphSONTokens.TRAVERSAL, getStepsAsList(pair.getValue1())); intermediates.add(intermediate); } m.put(GraphSONTokens.INTERMEDIATE, intermediates); if (strategyTraversals.isEmpty()) m.put(GraphSONTokens.FINAL, getStepsAsList(te.getOriginalTraversal())); else m.put(GraphSONTokens.FINAL, getStepsAsList(strategyTraversals.get(strategyTraversals.size() - 1).getValue1())); jsonGenerator.writeObject(m); }
Example 8
Source File: TraversalSerializersV2d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.PREDICATE, p instanceof ConnectiveP ? p instanceof AndP ? GraphSONTokens.AND : GraphSONTokens.OR : p.getBiPredicate().toString()); if (p instanceof ConnectiveP) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) { jsonGenerator.writeObject(predicate); } jsonGenerator.writeEndArray(); } else { if (p.getValue() instanceof Collection) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final Object object : (Collection) p.getValue()) { jsonGenerator.writeObject(object); } jsonGenerator.writeEndArray(); } else jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue()); } jsonGenerator.writeEndObject(); }
Example 9
Source File: CustomId.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serializeWithType(final CustomId customId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException, JsonProcessingException { // when the type is included add "class" as a key and then try to utilize as much of the // default serialization provided by jackson data-bind as possible. for example, write // the uuid as an object so that when jackson serializes it, it uses the uuid serializer // to write it out with the type. in this way, data-bind should be able to deserialize // it back when types are embedded. typeSerializer.writeTypePrefixForScalar(customId, jsonGenerator); final Map<String, Object> m = new HashMap<>(); m.put("cluster", customId.getCluster()); m.put("elementId", customId.getElementId()); jsonGenerator.writeObject(m); typeSerializer.writeTypeSuffixForScalar(customId, jsonGenerator); }
Example 10
Source File: GraphSONSerializersV2d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final TraversalMetrics traversalMetrics, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { // creation of the map enables all the fields to be properly written with their type if required final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.DURATION, traversalMetrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d); final List<Metrics> metrics = new ArrayList<>(); metrics.addAll(traversalMetrics.getMetrics()); m.put(GraphSONTokens.METRICS, metrics); jsonGenerator.writeObject(m); }
Example 11
Source File: TraversalSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final BulkSet bulkSet, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartArray(); for (Map.Entry entry : (Set<Map.Entry>) bulkSet.asBulk().entrySet()) { jsonGenerator.writeObject(entry.getKey()); jsonGenerator.writeObject(entry.getValue()); } jsonGenerator.writeEndArray(); }
Example 12
Source File: GraphSONSerializersV1d0.java From tinkerpop with Apache License 2.0 | 5 votes |
private static void serializeInternal(final TraversalMetrics traversalMetrics, final JsonGenerator jsonGenerator) throws IOException { // creation of the map enables all the fields to be properly written with their type if required final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.DURATION, traversalMetrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d); final List<Map<String, Object>> metrics = new ArrayList<>(); traversalMetrics.getMetrics().forEach(it -> metrics.add(metricsToMap(it))); m.put(GraphSONTokens.METRICS, metrics); jsonGenerator.writeObject(m); }
Example 13
Source File: HugeGraphSONModule.java From hugegraph with Apache License 2.0 | 5 votes |
@Override public void serialize(Optional optional, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException { if (optional.isPresent()) { jsonGenerator.writeObject(optional.get()); } else { jsonGenerator.writeObject(null); } }
Example 14
Source File: GraphSONSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final TraversalMetrics traversalMetrics, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { // creation of the map enables all the fields to be properly written with their type if required final Map<String, Object> m = new HashMap<>(); m.put(GraphSONTokens.DURATION, traversalMetrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d); final List<Metrics> metrics = new ArrayList<>(); metrics.addAll(traversalMetrics.getMetrics()); m.put(GraphSONTokens.METRICS, metrics); jsonGenerator.writeObject(m); }
Example 15
Source File: CustomId.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final CustomId customId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonGenerationException { final Map<String, Object> m = new HashMap<>(); m.put("cluster", customId.getCluster()); m.put("elementId", customId.getElementId()); jsonGenerator.writeObject(m); }
Example 16
Source File: JavaUtilSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final Set set, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { for(Object o : set) { jsonGenerator.writeObject(o); } }
Example 17
Source File: JavaUtilSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final Map.Entry entry, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final Map<Object,Object> m = new HashMap<>(); if (entry != null) m.put(entry.getKey(), entry.getValue()); jsonGenerator.writeObject(m); }
Example 18
Source File: JavaUtilSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final Map map, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { for(Map.Entry entry : (Set<Map.Entry>) map.entrySet()) { jsonGenerator.writeObject(entry.getKey()); jsonGenerator.writeObject(entry.getValue()); } }
Example 19
Source File: HugeGraphSONModule.java From hugegraph with Apache License 2.0 | 5 votes |
private static void writeEntry(JsonGenerator jsonGenerator, Map<HugeKeys, Object> schema) throws IOException { jsonGenerator.writeStartObject(); for (Map.Entry<HugeKeys, Object> entry : schema.entrySet()) { jsonGenerator.writeFieldName(entry.getKey().string()); jsonGenerator.writeObject(entry.getValue()); } jsonGenerator.writeEndObject(); }
Example 20
Source File: TraversalSerializersV2d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public void serialize(final Traversal traversal, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject(traversal.asAdmin().getBytecode()); }