The fundamental APIs are the generic objectToJson(Object)
and the very-specific
productToJson(OnixProduct)
.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
objectToJson
(Object object) Creates a JSON representation of an object using its public fields (i.e.static String
productToJson
(OnixProduct onixProduct) static String
productToJson
(OnixProduct onixProduct, boolean indent) Creates a JSON representation of anOnixProduct
object (i.e.static String
productToJson
(OnixProduct onixProduct, boolean indent, boolean sortSets) Creates a JSON representation of anOnixProduct
object (i.e.static String
static String
Creates a JSON representation of an object using either its public fields or itsOnixProduct
accessors, depending on its actual type.static String
Creates a JSON representation of an object using either its public fields or itsOnixProduct
accessors, depending on its actual type.
-
Constructor Details
-
JonixJson
public JonixJson()
-
-
Method Details
-
toJson
Creates a JSON representation of an object using either its public fields or itsOnixProduct
accessors, depending on its actual type.See
productToJson(OnixProduct, boolean)
andobjectToJson(Object)
for more details.- Parameters:
object
- object to serialize as JSON using its public fields or itsOnixProduct
accessorsindent
- whether the returned JSON string should be indented (OnixProduct
only)- Returns:
- JSON representation of the object
-
toJson
Creates a JSON representation of an object using either its public fields or itsOnixProduct
accessors, depending on its actual type.See
productToJson(OnixProduct, boolean, boolean)
andobjectToJson(Object)
for more details.- Parameters:
object
- object to serialize as JSON using its public fields or itsOnixProduct
accessorsindent
- whether the returned JSON string should be indented (OnixProduct
only)sortSets
- whether the returned JSON string should have its sets sorted (OnixProduct
only)- Returns:
- JSON representation of the object
-
toJson
- Parameters:
object
- object to serialize as JSON using its public fields or itsOnixProduct
accessors- Returns:
- indented JSON representation of the object
- See Also:
-
productToJson
Creates a JSON representation of anOnixProduct
object (i.e. low-level xml-parsed ONIX Product record).This JSON serializer is needed in addition to the more generic
objectToJson(Object)
becauseOnixProduct
s are populated "lazily". In other words, their internal fields get populated with actual values only when accessed explicitly (via accessor methods, that induce the population of theOnixComposite
they refer to). This is a design choice to make Jonix more performant and less memory hungry. However, for the underlying JSON serialization framework (Jackson
is this case), this laziness presents a problem, as no accessors are explicitly invoked, and nothing triggers population of the (private) fields that are accessed directly during serialization. Therefore, some advanced configuration of theJackson
serializer is required, which is exactly what this API does.- Parameters:
onixProduct
- anOnixProduct
object to serialize as JSONindent
- whether the returned JSON should be indented- Returns:
- JSON representation of the product
-
productToJson
Creates a JSON representation of anOnixProduct
object (i.e. low-level xml-parsed ONIX Product record).This JSON serializer is needed in addition to the more generic
objectToJson(Object)
becauseOnixProduct
s are populated "lazily". In other words, their internal fields get populated with actual values only when accessed explicitly (via accessor methods, that induce the population of theOnixComposite
they refer to). This is a design choice to make Jonix more performant and less memory hungry. However, for the underlying JSON serialization framework (Jackson
is this case), this laziness presents a problem, as no accessors are explicitly invoked, and nothing triggers population of the (private) fields that are accessed directly during serialization. Therefore, some advanced configuration of theJackson
serializer is required, which is exactly what this API does.- Parameters:
onixProduct
- anOnixProduct
object to serialize as JSONindent
- whether the returned JSON should be indentedsortSets
- whether the returned JSON should have its sets sorted- Returns:
- JSON representation of the product
-
productToJson
- Parameters:
onixProduct
- anOnixProduct
object to serialize as JSON- Returns:
- indented JSON representation of the product
- See Also:
-
objectToJson
Creates a JSON representation of an object using its public fields (i.e. NOT its getters or similar), therefore is suitable for theBaseProduct
family.- Parameters:
object
- Any Java object whose serializable values are stored in public fields- Returns:
- JSON representation of the object
-