List of usage examples for com.fasterxml.jackson.databind.node DoubleNode DoubleNode
public DoubleNode(double paramDouble)
From source file:com.mapr.synth.samplers.RandomWalkSampler.java
private FieldSampler constant(final double v) { return new FieldSampler() { private DoubleNode sd = new DoubleNode(v); @Override//from www.ja v a 2s . c om public JsonNode sample() { return sd; } }; }
From source file:com.turn.shapeshifter.AutoSerializer.java
/** * Returns the JSON representation of the value of a message's field. * * @param value the value to represent in JSON * @param field the descriptor of the value's field. * @param schemas a container for object schemas to use for formatting * fields that refer to other messages// ww w . j ava2 s . c o m * @throws SerializationException */ private JsonNode serializeValue(Object value, FieldDescriptor field, ReadableSchemaRegistry registry) throws SerializationException { JsonNode valueNode = NullNode.instance; switch (field.getType()) { case BOOL: valueNode = BooleanNode.valueOf((Boolean) value); break; case BYTES: break; case DOUBLE: valueNode = new DoubleNode((Double) value); break; case ENUM: EnumValueDescriptor enumValueDescriptor = (EnumValueDescriptor) value; String enumValue = enumValueDescriptor.getName(); String convertedValue = AutoSchema.PROTO_ENUM_CASE_FORMAT.to(AutoSchema.JSON_ENUM_CASE_FORMAT, enumValue); valueNode = new TextNode(convertedValue); break; case FLOAT: valueNode = new DoubleNode((Float) value); break; case GROUP: break; case FIXED32: case INT32: case SFIXED32: case SINT32: case UINT32: valueNode = new IntNode((Integer) value); break; case FIXED64: case INT64: case SFIXED64: case SINT64: case UINT64: valueNode = new LongNode((Long) value); break; case MESSAGE: Message messageValue = (Message) value; try { valueNode = registry.get(messageValue.getDescriptorForType()).getSerializer() .serialize(messageValue, registry); valueNode = valueNode.size() == 0 ? NullNode.instance : valueNode; } catch (SchemaObtentionException soe) { throw new SerializationException(soe); } break; case STRING: valueNode = new TextNode((String) value); break; default: break; } return valueNode; }
From source file:com.aol.one.patch.DefaultPatcherTest.java
@Test(expected = PatchException.class) public void testReplaceForFailure() throws PatchException { List<PatchOperation> operations = new ArrayList<>(); operations.add(new ReplaceOperation("/longField", new DoubleNode(10.1d))); patcher.patch(testObject, operations); }
From source file:com.aol.one.patch.DefaultPatcherTest.java
@Test public void testAddToMap() throws PatchException { List<PatchOperation> operations = new ArrayList<>(); DoubleNode displayNode = new DoubleNode(10.1d); operations.add(new AddOperation("/someIdMap/0", displayNode)); patcher.patch(testObject, operations); // verify/*from w w w . ja v a 2s . co m*/ verify(testObject.getSomeIdMap()).put("0", displayNode); }
From source file:com.aol.one.patch.DefaultPatcherTest.java
@Test public void testAddToList() throws PatchException { List<PatchOperation> operations = new ArrayList<>(); DoubleNode displayNode = new DoubleNode(10.1d); operations.add(new AddOperation("/someIdList/0", displayNode)); patcher.patch(testObject, operations); // verify/* ww w . ja v a2 s . co m*/ verify(testObject.getSomeIdList()).add(0, displayNode); }
From source file:com.aol.one.patch.DefaultPatcherTest.java
@Test public void testAddForSuccess() throws PatchException { List<PatchOperation> operations = new ArrayList<>(); operations.add(new AddOperation("/doubleField", new DoubleNode(10.1d))); operations.add(new AddOperation("/strField", new TextNode("1.1String"))); operations.add(new AddOperation("/child/doubleField", new DoubleNode(102.1))); patcher.patch(testObject, operations); Assert.assertEquals(10.1d, testObject.getDoubleField(), 0); Assert.assertEquals("1.1String", testObject.getStrField()); Assert.assertEquals(102.1d, testObject.getChild().getDoubleField(), 0); Assert.assertEquals("2string", testObject.getChild().getStrField()); }
From source file:com.turn.shapeshifter.SchemaSerializer.java
/** * Returns the JSON representation of the value of a message's field. * * @param value the value to represent in JSON * @param field the descriptor of the value's field. * @param schemas a container for object schemas to use for formatting fields that refer to * other messages// ww w . j av a 2 s. c o m * @throws SerializationException */ private JsonNode serializeValue(Object value, FieldDescriptor field, ReadableSchemaRegistry schemas) throws SerializationException { JsonNode valueNode = NullNode.instance; if (schema.getTransforms().containsKey(field.getName())) { return schema.getTransforms().get(field.getName()).serialize(value); } switch (field.getType()) { case BOOL: valueNode = BooleanNode.valueOf((Boolean) value); break; case BYTES: break; case DOUBLE: valueNode = new DoubleNode((Double) value); break; case ENUM: EnumValueDescriptor enumValueDescriptor = (EnumValueDescriptor) value; String enumValue = NamedSchema.PROTO_ENUM_CASE_FORMAT.to(schema.getEnumCaseFormat(), enumValueDescriptor.getName()); valueNode = new TextNode(enumValue); break; case FLOAT: valueNode = new DoubleNode((Float) value); break; case GROUP: break; case FIXED32: case INT32: case SFIXED32: case SINT32: case UINT32: valueNode = new IntNode((Integer) value); break; case FIXED64: case INT64: case SFIXED64: case SINT64: case UINT64: valueNode = new LongNode((Long) value); break; case MESSAGE: Message messageValue = (Message) value; Schema subSchema = null; if (schema.getSubObjectsSchemas().containsKey(field.getName())) { String schemaName = schema.getSubObjectsSchemas().get(field.getName()); if (schemas.contains(schemaName)) { subSchema = schemas.get(schemaName); } else { throw new IllegalStateException(); } } else { try { subSchema = schemas.get(field.getMessageType()); } catch (SchemaObtentionException soe) { throw new SerializationException(soe); } } valueNode = subSchema.getSerializer().serialize(messageValue, schemas); break; case STRING: valueNode = new TextNode((String) value); break; default: break; } return valueNode; }
From source file:com.turn.shapeshifter.NamedSchemaSerializer.java
/** * Returns the JSON representation of the value of a message's field. * * @param value the value to represent in JSON * @param field the descriptor of the value's field. * @param schemas a container for object schemas to use for formatting * fields that refer to other messages//from w ww . ja v a 2s . c om * @throws SerializationException */ private JsonNode serializeValue(Object value, FieldDescriptor field, ReadableSchemaRegistry schemas) throws SerializationException { JsonNode valueNode = NullNode.instance; if (schema.getTransforms().containsKey(field.getName())) { return schema.getTransforms().get(field.getName()).serialize(value); } switch (field.getType()) { case BOOL: valueNode = BooleanNode.valueOf((Boolean) value); break; case BYTES: byte[] bytes = ((ByteString) value).toByteArray(); String content = new String(); for (int i = 0; i < bytes.length; i++) { content += (char) bytes[i]; } valueNode = TextNode.valueOf(content); break; case DOUBLE: valueNode = new DoubleNode((Double) value); break; case ENUM: EnumValueDescriptor enumValueDescriptor = (EnumValueDescriptor) value; String enumValue = NamedSchema.PROTO_ENUM_CASE_FORMAT.to(schema.getEnumCaseFormat(), enumValueDescriptor.getName()); valueNode = new TextNode(enumValue); break; case FLOAT: valueNode = new DoubleNode((Float) value); break; case GROUP: break; case FIXED32: case INT32: case SFIXED32: case SINT32: case UINT32: valueNode = new IntNode((Integer) value); break; case FIXED64: case INT64: case SFIXED64: case SINT64: case UINT64: valueNode = schema.getSurfaceLongsAsStrings() ? new TextNode(((Long) value).toString()) : new LongNode((Long) value); break; case MESSAGE: Message messageValue = (Message) value; Schema subSchema = null; if (schema.getSubObjectsSchemas().containsKey(field.getName())) { String schemaName = schema.getSubObjectsSchemas().get(field.getName()); if (schemas.contains(schemaName)) { subSchema = schemas.get(schemaName); } else { throw new IllegalStateException(); } } else { try { subSchema = schemas.get(field.getMessageType()); } catch (SchemaObtentionException soe) { throw new SerializationException(soe); } } valueNode = subSchema.getSerializer().serialize(messageValue, schemas); valueNode = valueNode.size() == 0 ? NullNode.instance : valueNode; break; case STRING: valueNode = new TextNode((String) value); break; default: break; } return valueNode; }
From source file:com.aol.one.patch.DefaultPatcherTest.java
@Test public void testRemoveFromMap() throws PatchException { Map<String, JsonNode> map = new HashMap<>(); map.put("1", new DoubleNode(100)); map.put("2", new DoubleNode(200)); RemoveOperation removeOperation = new RemoveOperation("/1"); Patcher patcher = PatcherFactory.getDefaultPatcher(); patcher.patch(map, removeOperation); Assert.assertThat(map.get("1"), is(nullValue())); }
From source file:com.squarespace.template.Context.java
public JsonNode buildNode(double value) { return new DoubleNode(value); }