List of usage examples for com.fasterxml.jackson.core JsonGenerator writeObjectFieldStart
public final void writeObjectFieldStart(String fieldName) throws IOException, JsonGenerationException
From source file:com.msopentech.odatajclient.engine.data.json.GeospatialJSONHandler.java
private static void serializeCrs(final JsonGenerator jgen, final Node node) throws IOException { if (node.getAttributes().getNamedItem(ODataConstants.ATTR_SRSNAME) != null) { final String srsName = node.getAttributes().getNamedItem(ODataConstants.ATTR_SRSNAME).getTextContent(); final int prefIdx = srsName.indexOf(ODataConstants.JSON_GIS_URLPREFIX); final String crsValue = srsName.substring(prefIdx + ODataConstants.JSON_GIS_URLPREFIX.length()); jgen.writeObjectFieldStart(ODataConstants.JSON_CRS); jgen.writeStringField(ODataConstants.ATTR_TYPE, ODataConstants.NAME); jgen.writeObjectFieldStart(ODataConstants.PROPERTIES); jgen.writeStringField(ODataConstants.NAME, "EPSG:" + crsValue); jgen.writeEndObject();//from www .j av a2s. c om jgen.writeEndObject(); } }
From source file:com.msopentech.odatajclient.engine.data.json.DOMTreeUtilsV4.java
public static void writeSubtree(final ODataClient client, final JsonGenerator jgen, final Node content, final boolean propType) throws IOException { for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) { final String childName = XMLUtils.getSimpleName(child); final Node typeAttr = child.getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE); if (typeAttr != null && EdmSimpleType.isGeospatial(typeAttr.getTextContent())) { jgen.writeStringField(//from w w w . ja v a2 s .c om propType ? ODataConstants.JSON_TYPE : childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeObjectFieldStart(childName); GeospatialJSONHandler.serialize(jgen, (Element) child, typeAttr.getTextContent()); jgen.writeEndObject(); } else if (XMLUtils.hasOnlyTextChildNodes(child)) { if (child.hasChildNodes()) { final String out; if (typeAttr == null) { out = child.getChildNodes().item(0).getNodeValue(); } else { if (typeAttr.getTextContent().startsWith("Edm.")) { final EdmSimpleType type = EdmSimpleType.fromValue(typeAttr.getTextContent()); final ODataPrimitiveValue value = client.getPrimitiveValueBuilder().setType(type) .setText(child.getChildNodes().item(0).getNodeValue()).build(); out = value.toString(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, type.toString()); } else { // enum out = child.getTextContent(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } } jgen.writeStringField(childName, out); } else { if (child.getAttributes().getNamedItem(ODataConstants.ATTR_NULL) == null) { if (typeAttr != null && EdmSimpleType.String.toString().equals(typeAttr.getTextContent())) { jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeStringField(childName, StringUtils.EMPTY); } else { jgen.writeArrayFieldStart(childName); jgen.writeEndArray(); } } else { jgen.writeNullField(childName); } } } else { if (XMLUtils.hasElementsChildNode(child)) { jgen.writeArrayFieldStart(childName); for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) { if (XMLUtils.hasOnlyTextChildNodes(nephew)) { jgen.writeString(nephew.getChildNodes().item(0).getNodeValue()); } else { jgen.writeStartObject(); DOMTreeUtils.writeSubtree(client, jgen, nephew); jgen.writeEndObject(); } } jgen.writeEndArray(); } else { jgen.writeObjectFieldStart(childName); if (typeAttr != null) { jgen.writeStringField("@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } DOMTreeUtils.writeSubtree(client, jgen, child); jgen.writeEndObject(); } } } }
From source file:com.msopentech.odatajclient.engine.data.json.DOMTreeUtilsV3.java
/** * Serializes DOM content as JSON.//ww w. j a v a 2 s. c om * * @param client OData client. * @param jgen JSON generator. * @param content content. * @param propType whether to output type information in the way needed for property values or not. * @throws IOException in case of write error. */ public static void writeSubtree(final ODataClient client, final JsonGenerator jgen, final Node content, final boolean propType) throws IOException { for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) { final String childName = XMLUtils.getSimpleName(child); final Node typeAttr = child.getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE); if (typeAttr != null && EdmSimpleType.isGeospatial(typeAttr.getTextContent())) { jgen.writeStringField( propType ? ODataConstants.JSON_TYPE : childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeObjectFieldStart(childName); GeospatialJSONHandler.serialize(jgen, (Element) child, typeAttr.getTextContent()); jgen.writeEndObject(); } else if (XMLUtils.hasOnlyTextChildNodes(child)) { if (child.hasChildNodes()) { final String out; if (typeAttr == null) { out = child.getChildNodes().item(0).getNodeValue(); } else { final EdmSimpleType type = EdmSimpleType.fromValue(typeAttr.getTextContent()); final ODataPrimitiveValue value = client.getPrimitiveValueBuilder().setType(type) .setText(child.getChildNodes().item(0).getNodeValue()).build(); out = value.toString(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, type.toString()); } jgen.writeStringField(childName, out); } else { if (child.getAttributes().getNamedItem(ODataConstants.ATTR_NULL) == null) { if (typeAttr != null && EdmSimpleType.String.toString().equals(typeAttr.getTextContent())) { jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeStringField(childName, StringUtils.EMPTY); } else { jgen.writeArrayFieldStart(childName); jgen.writeEndArray(); } } else { jgen.writeNullField(childName); } } } else { if (XMLUtils.hasElementsChildNode(child)) { jgen.writeArrayFieldStart(childName); for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) { if (XMLUtils.hasOnlyTextChildNodes(nephew)) { jgen.writeString(nephew.getChildNodes().item(0).getNodeValue()); } else { jgen.writeStartObject(); DOMTreeUtils.writeSubtree(client, jgen, nephew); jgen.writeEndObject(); } } jgen.writeEndArray(); } else { jgen.writeObjectFieldStart(childName); if (typeAttr != null) { jgen.writeStringField(ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } DOMTreeUtils.writeSubtree(client, jgen, child); jgen.writeEndObject(); } } } }
From source file:com.msopentech.odatajclient.engine.data.json.DOMTreeUtils.java
/** * Serializes DOM content as JSON.//from w ww . j a va2 s . c o m * * @param jgen JSON generator. * @param content content. * @param propType whether to output type information in the way needed for property values or not. * @throws IOException in case of write error. */ public static void writeSubtree(final JsonGenerator jgen, final Node content, final boolean propType) throws IOException { for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) { final String childName = XMLUtils.getSimpleName(child); final Node typeAttr = child.getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE); if (typeAttr != null && EdmSimpleType.isGeospatial(typeAttr.getTextContent())) { jgen.writeStringField( propType ? ODataConstants.JSON_TYPE : childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeObjectFieldStart(childName); GeospatialJSONHandler.serialize(jgen, (Element) child, typeAttr.getTextContent()); jgen.writeEndObject(); } else if (XMLUtils.hasOnlyTextChildNodes(child)) { if (child.hasChildNodes()) { final String out; if (typeAttr == null) { out = child.getChildNodes().item(0).getNodeValue(); } else { final EdmSimpleType type = EdmSimpleType.fromValue(typeAttr.getTextContent()); final ODataPrimitiveValue value = new ODataPrimitiveValue.Builder().setType(type) .setText(child.getChildNodes().item(0).getNodeValue()).build(); out = value.toString(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, type.toString()); } jgen.writeStringField(childName, out); } else { if (child.getAttributes().getNamedItem(ODataConstants.ATTR_NULL) == null) { if (typeAttr != null && EdmSimpleType.String.toString().equals(typeAttr.getTextContent())) { jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeStringField(childName, StringUtils.EMPTY); } else { jgen.writeArrayFieldStart(childName); jgen.writeEndArray(); } } else { jgen.writeNullField(childName); } } } else { if (XMLUtils.hasElementsChildNode(child)) { jgen.writeArrayFieldStart(childName); for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) { if (XMLUtils.hasOnlyTextChildNodes(nephew)) { jgen.writeString(nephew.getChildNodes().item(0).getNodeValue()); } else { jgen.writeStartObject(); writeSubtree(jgen, nephew); jgen.writeEndObject(); } } jgen.writeEndArray(); } else { jgen.writeObjectFieldStart(childName); if (typeAttr != null) { jgen.writeStringField(ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } writeSubtree(jgen, child); jgen.writeEndObject(); } } } }
From source file:com.msopentech.odatajclient.engine.data.impl.JSONDOMTreeUtils.java
/** * Serializes DOM content as JSON.//from w w w . j a v a 2 s.com * * @param client OData client. * @param jgen JSON generator. * @param content content. * @param propType whether to output type information in the way needed for property values or not. * @throws IOException in case of write error. */ public static void writeSubtree(final ODataClient client, final JsonGenerator jgen, final Node content, final boolean propType) throws IOException { for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) { final String childName = XMLUtils.getSimpleName(child); final Node typeAttr = child.getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE); if (typeAttr != null && EdmSimpleType.isGeospatial(typeAttr.getTextContent())) { jgen.writeStringField( propType ? ODataConstants.JSON_TYPE : childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeObjectFieldStart(childName); GeospatialJSONHandler.serialize(client, jgen, (Element) child, typeAttr.getTextContent()); jgen.writeEndObject(); } else if (XMLUtils.hasOnlyTextChildNodes(child)) { if (child.hasChildNodes()) { final String out; if (typeAttr == null) { out = child.getChildNodes().item(0).getNodeValue(); } else { final EdmSimpleType type = EdmSimpleType.fromValue(typeAttr.getTextContent()); final ODataPrimitiveValue value = client.getPrimitiveValueBuilder().setType(type) .setText(child.getChildNodes().item(0).getNodeValue()).build(); out = value.toString(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, type.toString()); } jgen.writeStringField(childName, out); } else { if (child.getAttributes().getNamedItem(ODataConstants.ATTR_NULL) == null) { if (typeAttr != null && EdmSimpleType.String.toString().equals(typeAttr.getTextContent())) { jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeStringField(childName, StringUtils.EMPTY); } else { jgen.writeArrayFieldStart(childName); jgen.writeEndArray(); } } else { jgen.writeNullField(childName); } } } else { if (XMLUtils.hasElementsChildNode(child)) { jgen.writeArrayFieldStart(childName); for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) { if (XMLUtils.hasOnlyTextChildNodes(nephew)) { jgen.writeString(nephew.getChildNodes().item(0).getNodeValue()); } else { jgen.writeStartObject(); writeSubtree(client, jgen, nephew); jgen.writeEndObject(); } } jgen.writeEndArray(); } else { jgen.writeObjectFieldStart(childName); if (typeAttr != null) { jgen.writeStringField(ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } writeSubtree(client, jgen, child); jgen.writeEndObject(); } } } }
From source file:com.attribyte.essem.es.FieldAggregation.java
public void generate(final JsonGenerator generator) throws IOException { generator.writeObjectFieldStart(name); {/* w w w. j a v a 2 s . co m*/ generator.writeObjectFieldStart(type); { generator.writeStringField("field", field); } generator.writeEndObject(); } generator.writeEndObject(); }
From source file:org.dswarm.xsd2jsonschema.model.JSElement.java
void render(final JsonGenerator jgen) throws IOException { jgen.writeObjectFieldStart(getName()); jgen.writeStringField("type", getType()); renderDescription(jgen);/*from ww w .j a va 2 s .com*/ renderInternal(jgen); jgen.writeEndObject(); }
From source file:gaffer.serialisation.simple.json.hyperloglogplus.HyperLogLogPlusJsonSerialiser.java
private void _serialise(final HyperLogLogPlus hyperLogLogPlus, final JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeObjectFieldStart("hyperLogLogPlus"); jsonGenerator.writeObjectField(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD, hyperLogLogPlus.getBytes()); jsonGenerator.writeNumberField(HyperLogLogPlusJsonConstants.CARDINALITY_FIELD, hyperLogLogPlus.cardinality()); jsonGenerator.writeEndObject();/*from w ww . j av a 2s. com*/ }
From source file:com.attribyte.essem.es.BooleanTermQuery.java
@Override public void generate(final JsonGenerator generator) throws IOException { generator.writeStartObject();//from w w w.j a va 2 s.c o m generator.writeObjectFieldStart("term"); generator.writeBooleanField(term, value); generator.writeEndObject(); generator.writeEndObject(); }
From source file:com.attribyte.essem.es.IntTermQuery.java
@Override public void generate(final JsonGenerator generator) throws IOException { generator.writeStartObject();//from ww w . ja va 2 s. c om generator.writeObjectFieldStart("term"); generator.writeNumberField(term, value); generator.writeEndObject(); generator.writeEndObject(); }