Example usage for com.fasterxml.jackson.databind.node IntNode IntNode

List of usage examples for com.fasterxml.jackson.databind.node IntNode IntNode

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node IntNode IntNode.

Prototype

public IntNode(int paramInt) 

Source Link

Usage

From source file:com.github.tomakehurst.wiremock.http.BodyTest.java

@Test
public void constructsFromBytes() {
    Body body = Body.fromOneOf("this content".getBytes(), "not this content", new IntNode(1), "lskdjflsjdflks");

    assertThat(body.asString(), is("this content"));
    assertThat(body.isBinary(), is(true));
}

From source file:com.mapr.synth.samplers.IdSampler.java

@Override
public JsonNode sample() {
    return new IntNode(current.getAndIncrement());
}

From source file:com.github.tomakehurst.wiremock.http.BodyTest.java

@Test
public void constructsFromString() {
    Body body = Body.fromOneOf(null, "this content", new IntNode(1), "lskdjflsjdflks");

    assertThat(body.asString(), is("this content"));
    assertThat(body.isBinary(), is(false));
}

From source file:com.squarespace.template.GeneralUtilsTest.java

@Test
public void testIfString() {
    // Truth-y values
    JsonNode node = new IntNode(123);
    assertEquals(GeneralUtils.ifString(node, "000"), "123");
    node = new TextNode("456");
    assertEquals(GeneralUtils.ifString(node, "000"), "456");

    // False-y values
    node = new IntNode(0);
    assertEquals(GeneralUtils.ifString(node, "000"), "000");
    node = NullNode.getInstance();//w  w  w.j a v a 2s .  c  om
    assertEquals(GeneralUtils.ifString(node, "000"), "000");
}

From source file:com.redhat.lightblue.query.ValueTest.java

/**
 * Test of toJson method, of class Value.
 *//*from w  w  w .j  av  a 2s.  c  om*/
@Test
public void testToJson() throws IOException {
    // if in int range returns IntNode
    Value instance = new Value(10L);
    JsonNode expResult = new IntNode(10);
    JsonNode result = instance.toJson();
    assertEquals(expResult, result);

    instance = new Value(Long.MAX_VALUE);
    expResult = new LongNode(Long.MAX_VALUE);
    result = instance.toJson();
    assertEquals(expResult, result);

    instance = new Value(10.0D);
    expResult = new DoubleNode(10.0D);
    result = instance.toJson();
    assertEquals(expResult, result);

    instance = new Value(3.0F);
    expResult = new FloatNode(3.0F);
    result = instance.toJson();
    assertEquals(expResult, result);
}

From source file:com.github.tomakehurst.wiremock.http.BodyTest.java

@Test
public void constructsFromJson() {
    Body body = Body.fromOneOf(null, null, new IntNode(1), "lskdjflsjdflks");

    assertThat(body.asString(), is("1"));
    assertThat(body.isBinary(), is(false));
}

From source file:com.github.pjungermann.config.types.json.JsonConverterTest.java

@Test
public void from_hierarchicalJsonObject_convertToConfig() {
    ObjectNode level2 = new ObjectNode(JsonNodeFactory.instance);
    level2.set("an", new TextNode("entry"));

    ObjectNode level1 = new ObjectNode(JsonNodeFactory.instance);
    level1.set("level_2", level2);
    level1.set("another", new TextNode("value"));

    ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance);
    arrayNode.add(1);/*ww w. j  a  v a 2 s .c o  m*/
    arrayNode.add(2);
    arrayNode.add(3);

    ObjectNode json = new ObjectNode(JsonNodeFactory.instance);
    json.set("level_1", level1);
    json.set("boolean_true", BooleanNode.getTrue());
    json.set("boolean_false", BooleanNode.getFalse());
    json.set("number", new IntNode(123456));
    json.set("string", new TextNode("string value"));
    json.set("list", arrayNode);

    Config config = converter.from(json);

    assertEquals(true, config.get("boolean_true"));
    assertEquals(false, config.get("boolean_false"));
    assertEquals(123456, config.get("number"));
    assertEquals("string value", config.get("string"));
    assertEquals("entry", config.get("level_1.level_2.an"));
    assertEquals("value", config.get("level_1.another"));
    List list = (List) config.get("list");
    assertEquals(1, list.get(0));
    assertEquals(2, list.get(1));
    assertEquals(3, list.get(2));
}

From source file:com.mapr.synth.samplers.ForeignKeySampler.java

@Override
public JsonNode sample() {
    synchronized (this) {
        return new IntNode(base.sample());
    }
}

From source file:com.mapr.synth.samplers.IntegerSampler.java

@Override
public JsonNode sample() {
    synchronized (this) {
        int r = power >= 0 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
        if (power >= 0) {
            for (int i = 0; i <= power; i++) {
                r = Math.min(r, min + base.nextInt(max - min));
            }/*from   w w  w . j a  v a  2 s  .  c o  m*/
        } else {
            int n = -power;
            for (int i = 0; i <= n; i++) {
                r = Math.max(r, min + base.nextInt(max - min));
            }
        }
        return new IntNode(r);
    }
}

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//from   ww  w .  jav  a2s. c  om
 * @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;
}