public void writeStartElement(String prefix, String local, String ns) throws XMLStreamException { String parentKey = current.getTreeKey(); stack.push(current); String key = convention.createKey(prefix, ns, local); current = new JSONPropertyString(key, parentKey); }
public void writeEndDocument() throws XMLStreamException { if (!stack.isEmpty()) throw new XMLStreamException("Missing some closing tags."); // We know the root is a JSONPropertyObject so this cast is safe writeJSONObject((JSONObject)current.getValue()); try { writer.flush(); } catch (IOException e) { throw new XMLStreamException(e); } }
public void writeEndElement() throws XMLStreamException { if (stack.isEmpty()) throw new XMLStreamException("Too many closing tags."); current = stack.pop().withProperty(current); }
public JSONPropertyObject withProperty(JSONProperty property, boolean add) { Object value = property.getValue(); if(value instanceof String && !((String)value).isEmpty()) { value = convention.convertToJSONPrimitive((String)value); Object old = object.opt(property.getKey()); try { if(old != null) { object.put(property.getKey(), values); } else if(getSerializedAsArrays().contains(getPropertyArrayKey(property))) { JSONArray values = new JSONArray(); values.put(value); object.put(property.getKey(), values); } else { object.put(property.getKey(), value);
public void writeCharacters(String text) throws XMLStreamException { current.addText(text); }
private String getPropertyArrayKey(JSONProperty property) { return isArrayKeysWithSlashAvailable() ? property.getTreeKey() : property.getKey(); }
public JSONPropertyObject withProperty(JSONProperty property) { return withProperty(property, true); } }
public void writeAttribute(String prefix, String ns, String local, String value) throws XMLStreamException { String key = convention.isElement(prefix, ns, local) ? convention.createKey(prefix, ns, local) : convention.createAttributeKey(prefix, ns, local); JSONPropertyString prop = new JSONPropertyString(key, null); prop.addText(value); current = current.withProperty(prop, false); }