private ObjectNode updateMetricData(long nowMs, String hostName, ObjectNode testData) { ObjectNode data; data = testData.deepCopy(); // copy test data, modify it ObjectNode attNode = (ObjectNode) data.path( "attributes" ); attNode.put( "hostName", hostName ); attNode.put( "currentTimeMillis", nowMs ); ArrayNode timeStamps = (ArrayNode) data.path( "data" ).path( "timeStamp" ); for (int i = 0; i < timeStamps.size(); i++) { long offset = i * 30000; // timeStamps in reverse order LIFO. latest // time is first timeStamps.set( i, LongNode.valueOf( nowMs - offset ) ); } return data; }
public static JsonNode get( final PrimitiveObject obj ) throws IOException{ switch( obj.getPrimitiveType() ){ case BOOLEAN: return BooleanNode.valueOf( obj.getBoolean() ); case BYTE: return IntNode.valueOf( obj.getInt() ); case SHORT: return IntNode.valueOf( obj.getInt() ); case INTEGER: return IntNode.valueOf( obj.getInt() ); case LONG: return new LongNode( obj.getLong() ); case FLOAT: return new DoubleNode( obj.getDouble() ); case DOUBLE: return new DoubleNode( obj.getDouble() ); case STRING: return new TextNode( obj.getString() ); case BYTES: return new BinaryNode( obj.getBytes() ); default: return new TextNode( null ); } }
@Activate public void activate() { Serializer serializer = Serializer.using(KryoNamespaces.API, ObjectNode.class, ArrayNode.class, JsonNodeFactory.class, LinkedHashMap.class, TextNode.class, BooleanNode.class, LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class, NullNode.class); prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder() .withName(ONOS_USER_PREFERENCES) .withSerializer(serializer) .withRelaxedReadConsistency() .build(); prefsConsistentMap.addListener(prefsListener); prefs = prefsConsistentMap.asJavaMap(); register(core); log.info("Started"); }
@Activate public void activate() { KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() .register(KryoNamespaces.API) .register(ConfigKey.class, ObjectNode.class, ArrayNode.class, JsonNodeFactory.class, LinkedHashMap.class, TextNode.class, BooleanNode.class, LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class, NullNode.class); configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder() .withSerializer(Serializer.using(kryoBuilder.build())) .withName("onos-network-configs") .withRelaxedReadConsistency() .build(); configs.addListener(listener); log.info("Started"); }
@Test public void primitiveToJsonTest() { assertEquals(BooleanNode.TRUE, Serializer.toJson(true, TypeNode.fromString("bool"))); assertEquals(BooleanNode.FALSE, Serializer.toJson(false, TypeNode.fromString("bool"))); assertEquals(TextNode.valueOf("a"), Serializer.toJson('a', TypeNode.fromString("char"))); assertEquals(IntNode.valueOf(123), Serializer.toJson(123, TypeNode.fromString("int"))); assertEquals(LongNode.valueOf(123), Serializer.toJson(123L, TypeNode.fromString("long"))); assertEquals(DoubleNode.valueOf(123.0), Serializer.toJson(123.0, TypeNode.fromString("double"))); assertEquals(TextNode.valueOf("123"), Serializer.toJson("123", TypeNode.fromString("string"))); }
private Result decodePointer(int ctrlByte, int offset) { int pointerSize = ((ctrlByte >>> 3) & 0x3) + 1; int base = pointerSize == 4 ? (byte) 0 : (byte) (ctrlByte & 0x7); int packed = this.decodeInteger(base, pointerSize); long pointer = packed + this.pointerBase + this.pointerValueOffset[pointerSize]; if (Decoder.DEBUG) { Log.debug("Pointer size", String.valueOf(pointerSize)); Log.debug("Packed pointer", String.valueOf(packed)); Log.debug("Pointer base", this.pointerBase); Log.debug("Pointer value offset", this.pointerValueOffset[pointerSize]); Log.debug("Pointer to", String.valueOf(pointer)); } return new Result(new LongNode(pointer), offset + pointerSize); }
@Deprecated public static ValueNode toValueNode(Object value) { if (value == null) return NullNode.instance; if (value instanceof ValueNode) return (ValueNode) value; if (value instanceof Boolean) return BooleanNode.valueOf((boolean) value); else if (value instanceof Integer) return IntNode.valueOf((int) value); else if (value instanceof Long) return LongNode.valueOf((long) value); else if (value instanceof Double) return DoubleNode.valueOf((double) value); else if (value instanceof Float) return FloatNode.valueOf((float) value); return TextNode.valueOf(value.toString()); }
public static ValueNode toValueNode(Object value) { if (value == null) return NullNode.instance; if (value instanceof ValueNode) return (ValueNode) value; if (value instanceof Boolean) return BooleanNode.valueOf((boolean) value); else if (value instanceof Integer) return IntNode.valueOf((int) value); else if (value instanceof Long) return LongNode.valueOf((long) value); else if (value instanceof Double) return DoubleNode.valueOf((double) value); else if (value instanceof Float) return FloatNode.valueOf((float) value); return TextNode.valueOf(value.toString()); }
private static JobLaunchingData getJobLaunchingData(final JsonNode payload, final JsonNode jobJsonNode) { final String jobName = jobJsonNode.get("name").asText(); final JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); final JsonNode commercetools = payload.get("commercetools"); commercetools.fields().forEachRemaining(stringJsonNodeEntry -> { jobParametersBuilder.addString("commercetools." + stringJsonNodeEntry.getKey(), stringJsonNodeEntry.getValue().asText()); }); jobJsonNode.fields().forEachRemaining(jobField -> { //TODO prepare for other classes if (jobField.getValue() instanceof TextNode) { jobParametersBuilder.addString(jobField.getKey(), jobField.getValue().asText()); } else if (jobField.getValue() instanceof IntNode || jobField.getValue() instanceof LongNode) { jobParametersBuilder.addLong(jobField.getKey(), jobField.getValue().asLong()); } }); return new JobLaunchingData(jobName, jobParametersBuilder.toJobParameters()); }
/** * Get an Avro schema using {@link AvroUtils#wrapAsNullable(Schema)} by node type. * * @param node Json node. * @return an Avro schema using {@link AvroUtils#wrapAsNullable(Schema)} by node type. */ public Schema getAvroSchema(JsonNode node) { if (node instanceof TextNode) { return AvroUtils.wrapAsNullable(AvroUtils._string()); } else if (node instanceof IntNode) { return AvroUtils.wrapAsNullable(AvroUtils._int()); } else if (node instanceof LongNode) { return AvroUtils.wrapAsNullable(AvroUtils._long()); } else if (node instanceof DoubleNode) { return AvroUtils.wrapAsNullable(AvroUtils._double()); } else if (node instanceof BooleanNode) { return AvroUtils.wrapAsNullable(AvroUtils._boolean()); } else if (node instanceof NullNode) { return AvroUtils.wrapAsNullable(AvroUtils._string()); } else { return Schema.createRecord(getSubRecordRandomName(), null, null, false, getFields(node)); } }
@Override public JsonNode evaluate(JsonNode node) { JsonNode valueNode = super.evaluate(node); if(valueNode!=null && valueNode.isNumber()) { return LongNode.valueOf(Math.round(valueNode.asDouble())); } else if (valueNode!=null && valueNode.isTextual()){ try { Double doubleVal = Double.parseDouble(valueNode.asText()); return LongNode.valueOf(Math.round(doubleVal)); } catch(NumberFormatException e) { throw new UnsupportedExprException("Value not parseable to a number"); } } else { throw new UnsupportedExprException("Value not a number or text to parse to a number"); } }
@Override public void setProp(HasProp hasProp, String group, String key, Object value) { try { ObjectNode groupJSON = getOrCreateJsonGroup(hasProp, group); if (value == null) { groupJSON.put(key, NullNode.getInstance()); } else if (value instanceof Long) { groupJSON.put(key, LongNode.valueOf((Long) value)); } else if (value instanceof Double) { groupJSON.put(key, DoubleNode.valueOf((Double) value)); } else if (value instanceof Integer) { groupJSON.put(key, IntNode.valueOf((Integer) value)); } else if (value instanceof Float) { groupJSON.put(key, new DoubleNode((double) value)); } else if (value instanceof String) { groupJSON.put(key, TextNode.valueOf((String) value)); } else if (value instanceof Boolean) { groupJSON.put(key, BooleanNode.valueOf((Boolean) value)); } hasProp.setPropsJson(group, groupJSON.toString()); } catch (Exception e) { logSetProp(hasProp, group, key, value); } }
@Test public void unionLongInFloatRangeMax() throws JsonProcessingException, IOException { Schema schemaA = SchemaBuilder.builder().floatType(); Schema schemaB = SchemaBuilder.builder().intType(); Schema schema = SchemaBuilder.unionOf().type(schemaA).and().type(schemaB).endUnion(); JsonNode datum = new LongNode((long) Float.MAX_VALUE); UnionResolution unionResolution = new JasvornoConverter(model, UndeclaredFieldBehaviour.NO_MATCH) .resolveUnion(datum, schema.getTypes()); assertThat(unionResolution.matchType, is(MatchType.FULL)); assertThat(unionResolution.schema, is(schemaA)); }
@Test public void unionLongInFloatRangeMin() throws JsonProcessingException, IOException { Schema schemaA = SchemaBuilder.builder().floatType(); Schema schemaB = SchemaBuilder.builder().intType(); Schema schema = SchemaBuilder.unionOf().type(schemaA).and().type(schemaB).endUnion(); JsonNode datum = new LongNode((long) -Float.MAX_VALUE); UnionResolution unionResolution = new JasvornoConverter(model, UndeclaredFieldBehaviour.NO_MATCH) .resolveUnion(datum, schema.getTypes()); assertThat(unionResolution.matchType, is(MatchType.FULL)); assertThat(unionResolution.schema, is(schemaA)); }
@Test public void unionLongInsideFloatRange() throws JsonProcessingException, IOException { Schema schemaA = SchemaBuilder.builder().floatType(); Schema schemaB = SchemaBuilder.builder().intType(); Schema schema = SchemaBuilder.unionOf().type(schemaA).and().type(schemaB).endUnion(); JsonNode datum = new LongNode((long) (0.5 * Float.MAX_VALUE)); UnionResolution unionResolution = new JasvornoConverter(model, UndeclaredFieldBehaviour.NO_MATCH) .resolveUnion(datum, schema.getTypes()); assertThat(unionResolution.matchType, is(MatchType.FULL)); assertThat(unionResolution.schema, is(schemaA)); }
public static PrimitiveObject get( final JsonNode jsonNode ) throws IOException{ if( jsonNode instanceof TextNode ){ return new StringObj( ( (TextNode)jsonNode ).textValue() ); } else if( jsonNode instanceof BooleanNode ){ return new BooleanObj( ( (BooleanNode)jsonNode ).booleanValue() ); } else if( jsonNode instanceof IntNode ){ return new IntegerObj( ( (IntNode)jsonNode ).intValue() ); } else if( jsonNode instanceof LongNode ){ return new LongObj( ( (LongNode)jsonNode ).longValue() ); } else if( jsonNode instanceof DoubleNode ){ return new DoubleObj( ( (DoubleNode)jsonNode ).doubleValue() ); } else if( jsonNode instanceof BigIntegerNode ){ return new StringObj( ( (BigIntegerNode)jsonNode ).bigIntegerValue().toString() ); } else if( jsonNode instanceof DecimalNode ){ return new StringObj( ( (DecimalNode)jsonNode ).decimalValue().toString() ); } else if( jsonNode instanceof BinaryNode ){ return new BytesObj( ( (BinaryNode)jsonNode ).binaryValue() ); } else if( jsonNode instanceof POJONode ){ return new BytesObj( ( (POJONode)jsonNode ).binaryValue() ); } else if( jsonNode instanceof NullNode ){ return NullObj.getInstance(); } else if( jsonNode instanceof MissingNode ){ return NullObj.getInstance(); } else{ return new StringObj( jsonNode.toString() ); } }
public static JsonNode get( final Object obj ) throws IOException{ if( obj instanceof PrimitiveObject ){ return PrimitiveObjectToJsonNode.get( (PrimitiveObject)obj ); } else if( obj instanceof String ){ return new TextNode( (String)obj ); } else if( obj instanceof Boolean ){ return BooleanNode.valueOf( (Boolean)obj ); } else if( obj instanceof Short ){ return IntNode.valueOf( ( (Short)obj ).intValue() ); } else if( obj instanceof Integer ){ return IntNode.valueOf( (Integer)obj ); } else if( obj instanceof Long ){ return new LongNode( (Long)obj ); } else if( obj instanceof Float ){ return new DoubleNode( ( (Float)obj ).doubleValue() ); } else if( obj instanceof Double ){ return new DoubleNode( (Double)obj ); } else if( obj instanceof byte[] ){ return new BinaryNode( (byte[])obj ); } else if( obj == null ){ return NullNode.getInstance(); } else{ return new TextNode( obj.toString() ); } }
@Override public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) { if (!context.isLocationInfoEnabled() || logEvent.getSource() == null) { return null; } int sourceLineNumber = logEvent.getSource().getLineNumber(); return new LongNode(sourceLineNumber); }
@Test public void deserializesDataPoint() throws IOException { final JsonNode jsonNode = mock(JsonNode.class); given(objectCodec.readTree(same(jsonParser))).willReturn(jsonNode); given(jsonNode.get(0)).willReturn(LongNode.valueOf(123L)); given(jsonNode.get(1)).willReturn(DoubleNode.valueOf(234D)); given(jsonNode.get(2)).willReturn(IntNode.valueOf(5)); final QueryResponse.Tag.Result.DataPoint dataPoint = new QueryResponse.Tag.Result.DataPointDeserializer().deserialize(jsonParser, null); assertThat(dataPoint.getTimestamp().getTime(), is(123L)); assertThat(dataPoint.getMeasure(), is(234D)); assertThat(dataPoint.getQuality(), is(5)); }
/** * Serialize primtive values to JSON . */ static <T> JsonNode primitiveToJson(final T value, final TypeNode type) { final JsonNode result; // for BinaryTreeNode if (value == null) { return NullNode.instance; } switch (type.getValue()) { case BOOL: result = BooleanNode.valueOf((Boolean) value); break; case CHAR: result = TextNode.valueOf(value.toString()); break; case STRING: result = TextNode.valueOf((String) value); break; case DOUBLE: result = DoubleNode.valueOf((Double) value); break; case INT: result = IntNode.valueOf((Integer) value); break; case LONG: result = LongNode.valueOf((Long) value); break; default: throw new IllegalArgumentException("Unrecognized primitive type: " + type); } return result; }
/** * Get value from Json Node. * * @param node * @return value from Json Node */ private Object getValue(JsonNode node) { if (node instanceof TextNode) { return node.textValue(); } else if (node instanceof IntNode) { return node.intValue(); } else if (node instanceof LongNode) { return node.longValue(); } else if (node instanceof DoubleNode) { return node.doubleValue(); } else if (node instanceof BooleanNode) { return node.booleanValue(); } return null; }
/** * Safely serialize a value. * * @since 1.11.2 * @param encoder The <code>StenoEncoder</code> instance. * @param value The <code>Object</code> instance to safely serialize. */ public static void safeEncodeValue(final StringBuilder encoder, @Nullable final Object value) { if (value == null) { encoder.append("null"); } else if (value instanceof Map) { safeEncodeMap(encoder, (Map<?, ?>) value); } else if (value instanceof List) { safeEncodeList(encoder, (List<?>) value); } else if (value.getClass().isArray()) { safeEncodeArray(encoder, value); } else if (value instanceof LogValueMapFactory.LogValueMap) { safeEncodeLogValueMap(encoder, (LogValueMapFactory.LogValueMap) value); } else if (value instanceof Throwable) { safeEncodeThrowable(encoder, (Throwable) value); } else if (StenoSerializationHelper.isSimpleType(value)) { if (value instanceof Boolean) { encoder.append(BooleanNode.valueOf((Boolean) value).toString()); } else if (value instanceof Double) { encoder.append(DoubleNode.valueOf((Double) value).toString()); } else if (value instanceof Float) { encoder.append(FloatNode.valueOf((Float) value).toString()); } else if (value instanceof Long) { encoder.append(LongNode.valueOf((Long) value).toString()); } else if (value instanceof Integer) { encoder.append(IntNode.valueOf((Integer) value).toString()); } else { encoder.append(new TextNode(value.toString()).toString()); } } else { safeEncodeValue(encoder, LogReferenceOnly.of(value).toLogValue()); } }
/** * Add datapoint of long type value. * * @param time datapoint's timestamp * @param value datapoint's value * @return Datapoint */ public Datapoint addLongValue(long time, long value) { initialValues(); checkType(TsdbConstants.TYPE_LONG); values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new LongNode(value))); return this; }
/** * Add datapoint of double type value. * * @param time datapoint's timestamp * @param value datapoint's value * @return Datapoint */ public Datapoint addDoubleValue(long time, double value) { initialValues(); checkType(TsdbConstants.TYPE_DOUBLE); values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new DoubleNode(value))); return this; }
/** * Add datapoint of String type value. * * @param time datapoint's timestamp * @param value datapoint's value * @return Datapoint */ public Datapoint addStringValue(long time, String value) { initialValues(); checkType(TsdbConstants.TYPE_STRING); values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new TextNode(value))); return this; }
public Datapoint addBytesValue(long time, byte[] value) { initialValues(); if (values != null && !values.isEmpty() && (type == null || !type.equals(TsdbConstants.TYPE_BYTES))) { throw new IllegalStateException("There is already another type in datapoint, " + "could not add byte array type again"); } type = TsdbConstants.TYPE_BYTES; values.add(Lists.<JsonNode> newArrayList(new LongNode(time), new BinaryNode(value))); return this; }
public static Object unwrap(Object val) { // Can Jackson do this via // ObjectMapper.treeToValue()? The // spec is unclear Object result = val; ObjectMapper mapper = new ObjectMapper(); if (val instanceof ObjectNode) { result = mapper.convertValue((ObjectNode) val, Map.class); } else if (val instanceof ArrayNode) { result = mapper.convertValue((ObjectNode) val, List.class); } else if (val instanceof NullNode) { result = null; } else if (val instanceof BooleanNode) { result = ((BooleanNode) val).booleanValue(); } else if (val instanceof ShortNode) { result = ((ShortNode) val).shortValue(); } else if (val instanceof IntNode) { result = ((IntNode) val).intValue(); } else if (val instanceof LongNode) { result = ((LongNode) val).longValue(); } else if (val instanceof DoubleNode) { result = ((DoubleNode) val).doubleValue(); } else if (val instanceof FloatNode) { result = ((FloatNode) val).floatValue(); } else if (val instanceof BigIntegerNode) { result = ((BigIntegerNode) val).bigIntegerValue(); } else if (val instanceof DecimalNode) { result = ((DecimalNode) val).decimalValue(); } return result; }
@Activate public void activate() { Serializer serializer = Serializer.using(KryoNamespaces.API, ObjectNode.class, ArrayNode.class, JsonNodeFactory.class, LinkedHashMap.class, TextNode.class, BooleanNode.class, LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class, NullNode.class, UiSessionToken.class); prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder() .withName(ONOS_USER_PREFERENCES) .withSerializer(serializer) .withRelaxedReadConsistency() .build(); prefsConsistentMap.addListener(prefsListener); prefs = prefsConsistentMap.asJavaMap(); tokensConsistentMap = storageService.<UiSessionToken, String>consistentMapBuilder() .withName(ONOS_SESSION_TOKENS) .withSerializer(serializer) .withRelaxedReadConsistency() .build(); tokens = tokensConsistentMap.asJavaMap(); register(core); log.info("Started"); }
/** * Test of fromJson method, of class Value. */ @Test public void testFromJson() throws IOException { Value expResult = new Value(10L); JsonNode longNode = new LongNode(10); Value result = Value.fromJson(longNode); assertEquals(expResult, result); assertEquals("[\"test\"]", Value.fromJson(JsonUtils.json("[\"test\"]")).toJson().toString()); }
@Override public JsonNode build(String resource, String event, FileRemovalPayload payload) { ObjectNode base = (ObjectNode)super.build(resource, event, payload); base.set("attachment_id", new LongNode(payload.getAttachment().getKey().getId())); base.set("attachment_no", new LongNode(payload.getAttachment().getKey().getNo())); return base; }
public ObjectNode json() { ObjectNode node = new ObjectNode(instance); node.set("id", new LongNode(id)); node.set("title", new TextNode(title)); node.set("cover", new TextNode(cover)); return node; }
@Test(timeout = 4000) public void test0() throws Throwable { LongNode longNode0 = LongNode.valueOf(1331L); PostgresJSONJacksonJsonNodeConverter postgresJSONJacksonJsonNodeConverter0 = new PostgresJSONJacksonJsonNodeConverter(); // Undeclared exception! try { postgresJSONJacksonJsonNodeConverter0.to(longNode0); fail("Expecting exception: VerifyError"); } catch (VerifyError e) { // // Bad type on operand stack // Exception Details: // Location: // com/fasterxml/jackson/databind/ObjectMapper.<clinit>()V @62: invokespecial // Reason: // Type 'com/fasterxml/jackson/databind/util/StdDateFormat' (current frame, stack[8]) is not assignable to 'java/text/DateFormat' // Current Frame: // bci: @62 // flags: { } // locals: { } // stack: { uninitialized 35, uninitialized 35, null, 'com/fasterxml/jackson/databind/AnnotationIntrospector', 'com/fasterxml/jackson/databind/introspect/VisibilityChecker', null, 'com/fasterxml/jackson/databind/type/TypeFactory', null, 'com/fasterxml/jackson/databind/util/StdDateFormat', null, 'java/util/Locale', null, 'com/fasterxml/jackson/core/Base64Variant' } // Bytecode: // 0x0000000: 1304 16b8 06ef b304 14bb 06f1 59b7 06f2 // 0x0000010: b306 e5b8 06f5 b306 e7bb 06f7 59b7 06f8 // 0x0000020: b306 e9bb 0102 5901 b206 e5b2 06e7 01b8 // 0x0000030: 00f7 01b2 06fd 01b8 0703 01b8 0709 b707 // 0x0000040: 0cb3 00fc 1307 0eb8 0713 b113 070e b807 // 0x0000050: 13bf // Exception Handler Table: // bci [0, 75] => handler: 75 // Stackmap Table: // same_locals_1_stack_item_extended(@75,Object[#1587]) // assertThrownBy("com.chiralbehaviors.CoRE.postgres.PostgresJSONJacksonJsonNodeConverter", e); } }
public void set(long value) { this.node = new LongNode(value); }
private JsonNode json(long value) { return new LongNode(value); }
private Result decodeByType(Type type, int offset, int size) throws IOException { // MAP, ARRAY, and BOOLEAN do not use newOffset as we don't read the // next <code>size</code> bytes. For all other types, we do. int newOffset = offset + size; switch (type) { case MAP: return this.decodeMap(size, offset); case ARRAY: return this.decodeArray(size, offset); case BOOLEAN: return new Result(Decoder.decodeBoolean(size), offset); case UTF8_STRING: TextNode s = new TextNode(this.decodeString(size)); return new Result(s, newOffset); case DOUBLE: return new Result(this.decodeDouble(), newOffset); case FLOAT: return new Result(this.decodeFloat(), newOffset); case BYTES: BinaryNode b = new BinaryNode(this.getByteArray(size)); return new Result(b, newOffset); case UINT16: IntNode i = this.decodeUint16(size); return new Result(i, newOffset); case UINT32: LongNode l = this.decodeUint32(size); return new Result(l, newOffset); case INT32: IntNode int32 = this.decodeInt32(size); return new Result(int32, newOffset); case UINT64: BigIntegerNode bi = this.decodeBigInteger(size); return new Result(bi, newOffset); case UINT128: BigIntegerNode uint128 = this.decodeBigInteger(size); return new Result(uint128, newOffset); default: throw new InvalidDatabaseException( "Unknown or unexpected type: " + type.name()); } }
private LongNode decodeUint32(int size) { return new LongNode(this.decodeLong(size)); }
private JsonNode generateValue(LinkedList<String> path, ObjectNode schema, int index) { String stringPath = Utils.join(".", path.toArray(new String[path.size()])); List<Object> list = paths.get(stringPath); if (list != null) return Json7.toNode(list.get(random.nextInt(list.size()))); JsonNode values = Json7.get(schema, "_values"); if (values != null) { if (values.isArray()) { if (index < values.size()) return values.get(index); return values.get(random.nextInt(values.size())); } else return values; } JsonNode enumType = Json7.get(schema, "_enumType"); if (enumType != null) { if (types.containsKey(enumType.asText())) { List<String> typeValues = types.get(enumType.asText()); String value = typeValues.get(random.nextInt(typeValues.size())); return Json7.toNode(value); } } JsonNode examples = Json7.get(schema, "_examples"); if (examples != null) { if (examples.isArray()) { if (index < examples.size()) return examples.get(index); return examples.get(random.nextInt(examples.size())); } else return examples; } String type = schema.get("_type").asText(); if ("text".equals(type)) return TextNode.valueOf( "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness."); else if ("string".equals(type)) return TextNode.valueOf("RD5654GH78"); else if ("boolean".equals(type)) return BooleanNode.valueOf(random.nextBoolean()); else if ("integer".equals(type)) return IntNode.valueOf(random.nextInt()); else if ("long".equals(type)) return LongNode.valueOf(random.nextLong()); else if ("float".equals(type)) return FloatNode.valueOf(random.nextFloat()); else if ("double".equals(type)) return DoubleNode.valueOf(random.nextDouble()); else if ("date".equals(type)) return TextNode.valueOf("2015-09-09"); else if ("time".equals(type)) return TextNode.valueOf("15:30:00"); else if ("timestamp".equals(type)) return TextNode.valueOf("2015-01-09T15:37:00.123Z"); else if ("enum".equals(type)) return TextNode.valueOf("blue"); else if ("geopoint".equals(type)) return Json7.object("lat", 48 + random.nextDouble(), "lon", 2 + random.nextDouble()); else if ("object".equals(type)) return generateObject(path, schema, index); return NullNode.getInstance(); }
public Procedure(RegisterMessage register, long registrationID, Session session){ this.register = register; this.registrationID = LongNode.valueOf(registrationID); this.session = session; }
@Override public JsonNode toJSON(Long value) { return value == null ? NullNode.instance : new LongNode(value); }