public Comparable parseValue(JsonValue jsonValue) { if (jsonValue == null || jsonValue.getType().equals(JsonType.NULL)) { // Null return null; } // Boolean if (jsonValue.getType().equals(JsonType.BOOLEAN)) { return jsonValue.asBoolean(); } // Number if (jsonValue.getType().equals(JsonType.NUMBER)) { return jsonValue.asNumber(); } try { // Date return parseDate(jsonValue.asString()); } catch (Exception e1) { // String return jsonValue.asString(); } } }
public Comparable parseValue(JsonValue jsonValue) { if (jsonValue == null || jsonValue.getType().equals(JsonType.NULL)) { // Null return null; } // Boolean if (jsonValue.getType().equals(JsonType.BOOLEAN)) { return jsonValue.asBoolean(); } // Number if (jsonValue.getType().equals(JsonType.NUMBER)) { return jsonValue.asNumber(); } try { // Date return parseDate(jsonValue.asString()); } catch (Exception e1) { // String return jsonValue.asString(); } } }
@Test public void testDataSetLookupMarshalling() { DataSetLookup original = DataSetFactory.newDataSetLookupBuilder() .dataset("mydataset") .filter(OR(notEqualsTo("department", "IT"), greaterOrEqualsTo("amount", 100d))) .filter("department", notEqualsTo("IT")) .filter("amount", between(100d, 200d)) .filter("date", greaterThan(jsonMarshaller.parseDate("2018-01-01 00:00:00"))) .filter("country", isNull()) .group("department").select("Services") .group("date", "year").dynamic(DateIntervalType.YEAR, true) .column("date") .column("amount", AggregateFunctionType.SUM, "total") .sort("date", SortOrder.ASCENDING) .buildLookup(); JsonObject _jsonObj = jsonMarshaller.toJson(original); assertNotNull(_jsonObj.toString()); DataSetLookup unmarshalled = jsonMarshaller.fromJson(_jsonObj); assertEquals(unmarshalled, original); }
@Test public void testDataSetLookupMarshalling() { DataSetLookup original = DataSetLookupFactory.newDataSetLookupBuilder() .dataset("mydataset") .filter(OR(notEqualsTo("department", "IT"), greaterOrEqualsTo("amount", 100d))) .filter("department", notEqualsTo("IT")) .filter("amount", between(100d, 200d)) .filter("date", greaterThan(jsonMarshaller.parseDate("2018-01-01 00:00:00"))) .filter("country", isNull()) .group("department").select("Services") .group("date", "year").dynamic(DateIntervalType.YEAR, true) .column("date") .column("amount", AggregateFunctionType.SUM, "total") .sort("date", SortOrder.ASCENDING) .buildLookup(); JsonObject _jsonObj = jsonMarshaller.toJson(original); assertNotNull(_jsonObj.toString()); DataSetLookup unmarshalled = jsonMarshaller.fromJson(_jsonObj); assertEquals(unmarshalled, original); }