/** * Checks if xsi type needed to be specified */ private boolean xsiTypeNeeded(BeanT bean, XMLSerializer w, Object value, Class valueTypeClass) { if (!improvedXsiTypeHandling) // improved xsi type set return false; if (acc.isAdapted()) // accessor is not adapted return false; if (value == null) // value is not null return false; if (value.getClass().equals(valueTypeClass)) // value represented by different class return false; if (idRef) // IDREF return false; if (valueTypeClass.isPrimitive()) // is not primitive return false; return acc.isValueTypeAbstractable() || isNillableAbstract(bean, w.grammar, value, valueTypeClass); }
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }
/** * Checks if xsi type needed to be specified */ private boolean xsiTypeNeeded(BeanT bean, XMLSerializer w, Object value, Class valueTypeClass) { if (!improvedXsiTypeHandling) // improved xsi type set return false; if (acc.isAdapted()) // accessor is not adapted return false; if (value == null) // value is not null return false; if (value.getClass().equals(valueTypeClass)) // value represented by different class return false; if (idRef) // IDREF return false; if (valueTypeClass.isPrimitive()) // is not primitive return false; return acc.isValueTypeAbstractable() || isNillableAbstract(bean, w.grammar, value, valueTypeClass); }
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }
/** * Checks if xsi type needed to be specified */ private boolean xsiTypeNeeded(BeanT bean, XMLSerializer w, Object value, Class valueTypeClass) { if (!improvedXsiTypeHandling) // improved xsi type set return false; if (acc.isAdapted()) // accessor is not adapted return false; if (value == null) // value is not null return false; if (value.getClass().equals(valueTypeClass)) // value represented by different class return false; if (idRef) // IDREF return false; if (valueTypeClass.isPrimitive()) // is not primitive return false; return acc.isValueTypeAbstractable() || isNillableAbstract(bean, w.grammar, value, valueTypeClass); }
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }
/** * Checks if xsi type needed to be specified */ private boolean xsiTypeNeeded(BeanT bean, XMLSerializer w, Object value, Class valueTypeClass) { if (!improvedXsiTypeHandling) // improved xsi type set return false; if (acc.isAdapted()) // accessor is not adapted return false; if (value == null) // value is not null return false; if (value.getClass().equals(valueTypeClass)) // value represented by different class return false; if (idRef) // IDREF return false; if (valueTypeClass.isPrimitive()) // is not primitive return false; return acc.isValueTypeAbstractable() || isNillableAbstract(bean, w.grammar, value, valueTypeClass); }
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }