com.fasterxml.jackson.databind.node.POJONode Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.node.POJONode.
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: JsonCacheImpl.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public <T> T getObject(JsonPointer ptr, Class<T> type) throws CacheException { T result; if (root == null) { result = null; } else { JsonNode node = root.at(ptr); Object value = node.isPojo() && !JsonNode.class.isAssignableFrom(type) ? ((POJONode) node).getPojo() : node; if ((value != null) && (value.getClass() == type)) { result = (T) value; } else { result = mapper.convertValue(value, type); } } return result; }
Example #2
Source File: JsonNodeToPrimitiveObject.java From yosegi with Apache License 2.0 | 5 votes |
/** * Converts JsonNode to PrimitiveObject. */ public static PrimitiveObject get( final JsonNode jsonNode ) throws IOException { if ( jsonNode instanceof TextNode ) { return new StringObj( ( (TextNode)jsonNode ).textValue() ); } else if ( jsonNode instanceof BooleanNode ) { return new BooleanObj( ( (BooleanNode)jsonNode ).booleanValue() ); } else if ( jsonNode instanceof IntNode ) { return new IntegerObj( ( (IntNode)jsonNode ).intValue() ); } else if ( jsonNode instanceof LongNode ) { return new LongObj( ( (LongNode)jsonNode ).longValue() ); } else if ( jsonNode instanceof DoubleNode ) { return new DoubleObj( ( (DoubleNode)jsonNode ).doubleValue() ); } else if ( jsonNode instanceof BigIntegerNode ) { return new StringObj( ( (BigIntegerNode)jsonNode ).bigIntegerValue().toString() ); } else if ( jsonNode instanceof DecimalNode ) { return new StringObj( ( (DecimalNode)jsonNode ).decimalValue().toString() ); } else if ( jsonNode instanceof BinaryNode ) { return new BytesObj( ( (BinaryNode)jsonNode ).binaryValue() ); } else if ( jsonNode instanceof POJONode ) { return new BytesObj( ( (POJONode)jsonNode ).binaryValue() ); } else if ( jsonNode instanceof NullNode ) { return NullObj.getInstance(); } else if ( jsonNode instanceof MissingNode ) { return NullObj.getInstance(); } else { return new StringObj( jsonNode.toString() ); } }
Example #3
Source File: JsonCacheImpl.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public Object get(JsonPointer ptr) throws CacheException { Object result; if (root == null) { result = null; } else { try { JsonNode node = root.at(ptr); switch (node.getNodeType()) { case ARRAY: case OBJECT: result = node; break; case BINARY: result = node.binaryValue(); break; case BOOLEAN: result = node.booleanValue(); break; case NUMBER: result = node.numberValue(); break; case POJO: result = ((POJONode) node).getPojo(); break; case STRING: result = node.textValue(); break; default: result = null; break; } } catch (IOException e) { throw new CacheException(e); } } return result; }
Example #4
Source File: JacksonObjectScalarMapper.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Override public GraphQLScalarType toGraphQLInputType(AnnotatedType javaType, Set<Class<? extends TypeMapper>> mappersToSkip, TypeMappingEnvironment env) { if (POJONode.class.equals(javaType.getType())) { throw new UnsupportedOperationException(POJONode.class.getSimpleName() + " can not be used as input"); } return toGraphQLType(javaType, mappersToSkip, env); }
Example #5
Source File: JacksonObjectScalars.java From graphql-spqr with Apache License 2.0 | 5 votes |
private static Map<Type, GraphQLScalarType> getScalarMapping() { Map<Type, GraphQLScalarType> scalarMapping = new HashMap<>(); scalarMapping.put(ObjectNode.class, JsonObjectNode); scalarMapping.put(POJONode.class, JsonObjectNode); scalarMapping.put(JsonNode.class, JsonAnyNode); return Collections.unmodifiableMap(scalarMapping); }
Example #6
Source File: JacksonModule.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Override public void setUp(SetupContext context) { if (!getTypeMappers().isEmpty()) { context.getSchemaGenerator().withTypeMappersPrepended(getTypeMappers().toArray(new TypeMapper[0])); } if (!getOutputConverters().isEmpty()) { context.getSchemaGenerator().withOutputConvertersPrepended(getOutputConverters().toArray(new OutputConverter[0])); } if (!getInputConverters().isEmpty()) { context.getSchemaGenerator().withInputConvertersPrepended(getInputConverters().toArray(new InputConverter[0])); } context.getSchemaGenerator().withTypeComparators(new SynonymBaseTypeComparator(ObjectNode.class, POJONode.class)); context.getSchemaGenerator().withTypeComparators(new SynonymBaseTypeComparator(DecimalNode.class, NumericNode.class)); }
Example #7
Source File: JsonTypeMappingTest.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Test public void testJacksonTypeMapping() { GraphQLSchemaGenerator gen = new TestSchemaGenerator() .withOperationsFromSingleton(new JacksonService()); GraphQLSchema schema = gen.generate(); GraphQL exe = GraphQLRuntime.newGraphQL(schema).build(); ExecutionResult result = exe.execute( "{item(in: {" + " obj: {one: \"two\"}," + " any: 3.3," + " binary: \"UmFuZG9tIGp1bms=\"," + " text: \"some text\"," + " integer: 123," + " dbl: 12.123," + " bigInt: 99999999999," + " array: [333, {one: \"two\"}]}) {" + " obj, any, text, binary, integer, dbl, bigInt, array, pojo" + " }" + "}"); assertNoErrors(result); assertTypeAtPathIs(ObjectNode.class, result, "item.obj"); assertTypeAtPathIs(POJONode.class, result, "item.pojo"); assertTypeAtPathIs(Number.class, result, "item.any"); assertTypeAtPathIs(String.class, result, "item.binary"); assertTypeAtPathIs(String.class, result, "item.text"); assertTypeAtPathIs(Integer.class, result, "item.integer"); assertTypeAtPathIs(Double.class, result, "item.dbl"); assertTypeAtPathIs(BigInteger.class, result, "item.bigInt"); assertTypeAtPathIs(List.class, result, "item.array"); assertTypeAtPathIs(BigInteger.class, result, "item.array.0"); assertTypeAtPathIs(ObjectNode.class, result, "item.array.1"); }
Example #8
Source File: TestJsonNodeToPrimitiveObject.java From yosegi with Apache License 2.0 | 4 votes |
@Test public void T_get_binaryObject_withPOJONode() throws IOException { PrimitiveObject obj = JsonNodeToPrimitiveObject.get( new POJONode( "a".getBytes() ) ); assertTrue( ( obj instanceof BytesObj ) ); }
Example #9
Source File: JacksonJsonToObjectConverterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Test public void convertPojoReturnsPojo() throws JsonProcessingException { String json = "{\"id\":1,\"name\":\"Jon Doe\"}"; POJONode mockJsonNode = mock(POJONode.class); ObjectMapper mockObjectMapper = mock(ObjectMapper.class); Customer jonDoe = Customer.newCustomer(1L, "Jon Doe"); doReturn(mockObjectMapper).when(this.converter).getObjectMapper(); doReturn(mockJsonNode).when(mockObjectMapper).readTree(eq(json)); doReturn(jonDoe).when(mockJsonNode).getPojo(); assertThat(this.converter.convert(json)).isEqualTo(jonDoe); verify(this.converter, times(1)).getObjectMapper(); verify(mockObjectMapper, times(1)).readTree(eq(json)); verify(mockJsonNode, times(1)).getPojo(); }
Example #10
Source File: JsonTypeMappingTest.java From graphql-spqr with Apache License 2.0 | 4 votes |
public POJONode getPojo() { return new POJONode(new Street("Fake Street", 123)); }
Example #11
Source File: DistributedWorkplaceStore.java From onos with Apache License 2.0 | 4 votes |
@Activate public void activate() { appId = coreService.registerApplication("org.onosproject.workplacestore"); log.info("appId=" + appId); KryoNamespace workplaceNamespace = KryoNamespace.newBuilder() .register(KryoNamespaces.API) .register(WorkflowData.class) .register(Workplace.class) .register(DefaultWorkplace.class) .register(WorkflowContext.class) .register(DefaultWorkflowContext.class) .register(SystemWorkflowContext.class) .register(WorkflowState.class) .register(ProgramCounter.class) .register(DataModelTree.class) .register(JsonDataModelTree.class) .register(List.class) .register(ArrayList.class) .register(JsonNode.class) .register(ObjectNode.class) .register(TextNode.class) .register(LinkedHashMap.class) .register(ArrayNode.class) .register(BaseJsonNode.class) .register(BigIntegerNode.class) .register(BinaryNode.class) .register(BooleanNode.class) .register(ContainerNode.class) .register(DecimalNode.class) .register(DoubleNode.class) .register(FloatNode.class) .register(IntNode.class) .register(JsonNodeType.class) .register(LongNode.class) .register(MissingNode.class) .register(NullNode.class) .register(NumericNode.class) .register(POJONode.class) .register(ShortNode.class) .register(ValueNode.class) .register(JsonNodeCreator.class) .register(JsonNodeFactory.class) .build(); localWorkplaceMap.clear(); workplaceMap = storageService.<String, WorkflowData>consistentMapBuilder() .withSerializer(Serializer.using(workplaceNamespace)) .withName("workplace-map") .withApplicationId(appId) .build(); workplaceMap.addListener(workplaceMapEventListener); localContextMap.clear(); contextMap = storageService.<String, WorkflowData>consistentMapBuilder() .withSerializer(Serializer.using(workplaceNamespace)) .withName("workflow-context-map") .withApplicationId(appId) .build(); contextMap.addListener(contextMapEventListener); workplaceMapEventListener.syncLocal(); contextMapEventListener.syncLocal(); log.info("Started"); }
Example #12
Source File: JacksonJsonToObjectConverterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 3 votes |
@Test public void isPojoWithPojoNode() { POJONode mockPojoNode = mock(POJONode.class); assertThat(this.converter.isPojo(mockPojoNode)).isTrue(); verifyNoInteractions(mockPojoNode); }
Example #13
Source File: JacksonJsonToObjectConverter.java From spring-boot-data-geode with Apache License 2.0 | 2 votes |
/** * Null-safe method to determine whether the given {@link JsonNode} represents a {@link Object POJO}. * * @param jsonNode {@link JsonNode} to evaluate. * @return a boolean value indicating whether the given {@link JsonNode} represents a {@link Object POJO}. * @see com.fasterxml.jackson.databind.JsonNode */ boolean isPojo(@Nullable JsonNode jsonNode) { return jsonNode != null && (jsonNode instanceof POJONode || jsonNode.isPojo() || JsonNodeType.POJO.equals(jsonNode.getNodeType())); }