private void writeScalarPropertyValue(JsonGenerator jg, Type type, Object value) throws IOException { if (value == null) { jg.writeNull(); } else if (type instanceof BooleanType) { jg.writeBoolean((Boolean) value); } else if (type instanceof LongType) { jg.writeNumber(((Number) value).longValue()); // value may be a DeltaLong } else if (type instanceof DoubleType) { jg.writeNumber((Double) value); } else if (type instanceof IntegerType) { jg.writeNumber((Integer) value); } else if (type instanceof BinaryType) { jg.writeBinary((byte[]) value); } else { jg.writeString(type.encode(value)); } }
jg.writeString(type.encode(v));
protected void writeListProperty(JsonGenerator jg, Property prop, PropertyConsumer fieldNameWriter) throws PropertyException, IOException { // test if array/list is empty - don't write empty case if (!writeEmpty && (prop == null || (prop instanceof ArrayProperty && prop.getValue() == null) || (prop instanceof ListProperty && prop.getChildren().isEmpty()))) { return; } fieldNameWriter.accept(jg, prop); jg.writeStartArray(); if (prop instanceof ArrayProperty) { Object[] ar = (Object[]) prop.getValue(); if (ar == null) { jg.writeEndArray(); return; } Type type = ((ListType) prop.getType()).getFieldType(); for (Object o : ar) { jg.writeString(type.encode(o)); } } else { for (Property p : prop.getChildren()) { // it's a list of complex object, don't write field names writeProperty(jg, p, PropertyConsumer.nothing()); } } jg.writeEndArray(); }
String encodedValue = type.encode(value); if (encodedValue != null) {
/** * Create a schema from a ComplexType * * @since 5.7 * @param complexType * @param name * @param ns */ public SchemaImpl(ComplexType complexType, String name, Namespace ns, boolean isVersionWritabe) { super(null, SchemaNames.SCHEMAS, name, ns); this.isVersionWritabe = isVersionWritabe; if (complexType != null) { for (Field field : complexType.getFields()) { QName fieldname = QName.valueOf(field.getName().getLocalName(), ns.prefix); Type type = field.getType(); String defaultValue = type.encode(field.getDefaultValue()); Set<Constraint> constraint = field.getConstraints(); FieldImpl newField = new FieldImpl(fieldname, this, type, defaultValue, 0, constraint); newField.setConstant(field.isConstant()); addField(newField); } } }
element.addAttribute(TYPE_ATTRIBUTE, getSimpleTypeId(type)); if (value != null) { element.addText(type.encode(value));