Java Code Examples for com.fasterxml.jackson.databind.node.JsonNodeFactory#withExactBigDecimals()

The following examples show how to use com.fasterxml.jackson.databind.node.JsonNodeFactory#withExactBigDecimals() . 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: FileSampler.java    From log-synth with Apache License 2.0 6 votes vote down vote up
private void readDelimitedData(String lookup, List<String> lines) {
    Splitter splitter;
    if (lookup.matches(".*\\.csv")) {
        splitter = Splitter.on(",");
    } else if (lookup.matches(".*\\.tsv")) {
        splitter = Splitter.on("\t");
    } else {
        throw new IllegalArgumentException("Must have file with .csv, .tsv or .json suffix");
    }

    List<String> names = Lists.newArrayList(splitter.split(lines.get(0)));
    JsonNodeFactory nf = JsonNodeFactory.withExactBigDecimals(false);
    ArrayNode localData = nf.arrayNode();
    for (String line : lines.subList(1, lines.size())) {
        ObjectNode r = nf.objectNode();
        List<String> fields = Lists.newArrayList(splitter.split(line));
        Preconditions.checkState(names.size() == fields.size(), "Wrong number of fields, expected ", names.size(), fields.size());
        Iterator<String> ix = names.iterator();
        for (String field : fields) {
            r.put(ix.next(), field);
        }
        localData.add(r);
    }
    data = localData;
}
 
Example 2
Source File: RandomWalkSampler.java    From log-synth with Apache License 2.0 6 votes vote down vote up
@Override
public JsonNode sample() {
    double step;
    if (stepDistribution == null) {
        step = rand.nextGaussian() * sd.sample().asDouble() + mean.sample().asDouble();
    } else {
        step = stepDistribution.sample().asDouble();
    }
    double newState = state.addAndGet(step);

    if (verbose) {
        ObjectNode r = new ObjectNode(JsonNodeFactory.withExactBigDecimals(false));
        r.set("value", new DoubleNode(newState));
        r.set("step", new DoubleNode(step));
        return r;
    } else {
        return new DoubleNode(newState);
    }
}
 
Example 3
Source File: VertxRestServiceTest.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrimitives() throws Exception {
  JsonNodeFactory jsonFactory = JsonNodeFactory.withExactBigDecimals(true);
  JsonNode json = jsonFactory.objectNode()
      .set("protocol", jsonFactory.objectNode()
          .put("type", "multi-primary")
          .put("backups", 2));

  given()
      .spec(specs.get(0))
      .contentType(ContentType.JSON)
      .body(json)
      .when()
      .post("lock/test-primitive")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .when()
      .get("primitives")
      .then()
      .statusCode(200)
      .body("test-primitive.type", equalTo("lock"));

  given()
      .spec(specs.get(1))
      .when()
      .get("lock")
      .then()
      .statusCode(200)
      .body("test-primitive.type", equalTo("lock"));
}
 
Example 4
Source File: VertxRestServiceTest.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Test
public void testLock() throws Exception {
  JsonNodeFactory jsonFactory = JsonNodeFactory.withExactBigDecimals(true);
  JsonNode json = jsonFactory.objectNode()
      .set("protocol", jsonFactory.objectNode()
          .put("type", "multi-primary")
          .put("backups", 2));

  given()
      .spec(specs.get(0))
      .contentType(ContentType.JSON)
      .body(json)
      .when()
      .post("atomic-lock/test-lock")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(0))
      .when()
      .post("atomic-lock/test-lock/lock")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(0))
      .when()
      .delete("atomic-lock/test-lock/lock")
      .then()
      .statusCode(200);
}
 
Example 5
Source File: VertxRestServiceTest.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Test
public void testSemaphore() throws Exception {
  JsonNodeFactory jsonFactory = JsonNodeFactory.withExactBigDecimals(true);
  JsonNode json = jsonFactory.objectNode()
      .put("initial-capacity", 2)
      .set("protocol", jsonFactory.objectNode()
          .put("type", "multi-primary")
          .put("backups", 2));

  given()
      .spec(specs.get(0))
      .contentType(ContentType.JSON)
      .body(json)
      .when()
      .post("semaphore/test-semaphore")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(0))
      .when()
      .get("semaphore/test-semaphore/permits")
      .then()
      .statusCode(200)
      .body(equalTo("2"));

  given()
      .spec(specs.get(0))
      .contentType(ContentType.JSON)
      .when()
      .post("semaphore/test-semaphore/acquire")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .contentType(ContentType.JSON)
      .when()
      .post("semaphore/test-semaphore/acquire")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(2))
      .when()
      .get("semaphore/test-semaphore/permits")
      .then()
      .body(equalTo("0"));

  given()
      .spec(specs.get(1))
      .contentType(ContentType.JSON)
      .when()
      .post("semaphore/test-semaphore/release")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(0))
      .when()
      .get("semaphore/test-semaphore/permits")
      .then()
      .body(equalTo("1"));

  given()
      .spec(specs.get(1))
      .when()
      .get("semaphore/test-semaphore/permits")
      .then()
      .body(equalTo("1"));
}
 
Example 6
Source File: VertxRestServiceTest.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Test
public void testValue() throws Exception {
  JsonNodeFactory jsonFactory = JsonNodeFactory.withExactBigDecimals(true);
  JsonNode json = jsonFactory.objectNode()
      .set("protocol", jsonFactory.objectNode()
          .put("type", "multi-primary")
          .put("backups", 2));

  given()
      .spec(specs.get(0))
      .contentType(ContentType.JSON)
      .body(json)
      .when()
      .post("atomic-value/test-value")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .when()
      .get("atomic-value/test-value/value")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .contentType(ContentType.TEXT)
      .body("Hello world!")
      .when()
      .post("atomic-value/test-value/value")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .when()
      .get("atomic-value/test-value/value")
      .then()
      .statusCode(200)
      .body(equalTo("Hello world!"));
}
 
Example 7
Source File: VertxRestServiceTest.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Test
public void testMap() throws Exception {
  JsonNodeFactory jsonFactory = JsonNodeFactory.withExactBigDecimals(true);
  ObjectNode json = jsonFactory.objectNode()
      .put("null-values", false);
  json.set("protocol", jsonFactory.objectNode()
      .put("type", "multi-primary")
      .put("backups", 2));
  json.set("cache", jsonFactory.objectNode()
      .put("enabled", true));

  given()
      .spec(specs.get(0))
      .contentType(ContentType.JSON)
      .body(json)
      .when()
      .post("atomic-map/test")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .when()
      .get("atomic-map/test/foo")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(0))
      .body("Hello world!")
      .when()
      .put("atomic-map/test/foo")
      .then()
      .statusCode(200);

  given()
      .spec(specs.get(1))
      .when()
      .get("atomic-map/test/foo")
      .then()
      .statusCode(200)
      .assertThat()
      .body("value", equalTo("Hello world!"));
}