use of elemental.json.JsonBoolean in project flow by vaadin.
the class JsonSerializerTest method serializeBasicTypes_returnJsonBasicTypes.
@Test
public void serializeBasicTypes_returnJsonBasicTypes() {
JsonValue json = JsonSerializer.toJson("someString");
Assert.assertTrue("The JsonValue should be instanceof JsonString", json instanceof JsonString);
Assert.assertEquals("someString", json.asString());
json = JsonSerializer.toJson(0);
Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
Assert.assertEquals(0.0, json.asNumber(), PRECISION);
json = JsonSerializer.toJson(0.0);
Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
Assert.assertEquals(0.0, json.asNumber(), PRECISION);
json = JsonSerializer.toJson(0l);
Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
Assert.assertEquals(0.0, json.asNumber(), PRECISION);
json = JsonSerializer.toJson((byte) 0);
Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
Assert.assertEquals(0.0, json.asNumber(), PRECISION);
json = JsonSerializer.toJson((short) 0);
Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
Assert.assertEquals(0.0, json.asNumber(), PRECISION);
json = JsonSerializer.toJson(true);
Assert.assertTrue("The JsonValue should be instanceof JsonBoolean", json instanceof JsonBoolean);
Assert.assertTrue(json.asBoolean());
json = JsonSerializer.toJson(false);
Assert.assertTrue("The JsonValue should be instanceof JsonBoolean", json instanceof JsonBoolean);
Assert.assertFalse(json.asBoolean());
json = JsonSerializer.toJson(SomeEnum.SOME_VALUE_1);
Assert.assertTrue("The JsonValue should be instanceof JsonString", json instanceof JsonString);
Assert.assertEquals(SomeEnum.SOME_VALUE_1.name(), json.asString());
}
use of elemental.json.JsonBoolean in project flow by vaadin.
the class JsonCodecTest method decodeAs_booleanJson.
@Test
public void decodeAs_booleanJson() {
JsonBoolean json = Json.create(true);
Assert.assertTrue(JsonCodec.decodeAs(json, Boolean.class));
Assert.assertEquals("true", JsonCodec.decodeAs(json, String.class));
Assert.assertEquals(Integer.valueOf(1), JsonCodec.decodeAs(json, Integer.class));
Assert.assertEquals(Double.valueOf(1.0), JsonCodec.decodeAs(json, Double.class));
Assert.assertEquals(json, JsonCodec.decodeAs(json, JsonValue.class));
}
Aggregations