use of sqlite.kripton58.BeanInner in project kripton by xcesco.
the class BeanBeanBindMap method serializeOnJackson.
@Override
public int serializeOnJackson(BeanBean object, JsonGenerator jacksonSerializer) throws Exception {
jacksonSerializer.writeStartObject();
int fieldCount = 0;
// Serialized Field:
// field id (mapped with "id")
fieldCount++;
jacksonSerializer.writeNumberField("id", object.id);
// field value (mapped with "value")
if (object.value != null) {
fieldCount++;
int n = object.value.size();
BeanInner item;
// write wrapper tag
jacksonSerializer.writeFieldName("value");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = object.value.get(i);
if (item == null) {
jacksonSerializer.writeNull();
} else {
beanInnerBindMap.serializeOnJackson(item, jacksonSerializer);
}
}
jacksonSerializer.writeEndArray();
}
// field value2 (mapped with "value2")
if (object.value2 != null) {
fieldCount++;
int n = object.value2.size();
BeanInner item;
// write wrapper tag
jacksonSerializer.writeFieldName("value2");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = object.value2.get(i);
if (item == null) {
jacksonSerializer.writeNull();
} else {
beanInnerBindMap.serializeOnJackson(item, jacksonSerializer);
}
}
jacksonSerializer.writeEndArray();
}
jacksonSerializer.writeEndObject();
return fieldCount;
}
use of sqlite.kripton58.BeanInner in project kripton by xcesco.
the class BeanBeanBindMap method parseOnJackson.
/**
* parse with jackson
*/
@Override
public BeanBean parseOnJackson(JsonParser jacksonParser) throws Exception {
BeanBean instance = new BeanBean();
String fieldName;
if (jacksonParser.currentToken() == null) {
jacksonParser.nextToken();
}
if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
jacksonParser.skipChildren();
return instance;
}
while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
fieldName = jacksonParser.getCurrentName();
jacksonParser.nextToken();
// Parse fields:
switch(fieldName) {
case "id":
// field id (mapped with "id")
instance.id = jacksonParser.getLongValue();
break;
case "value":
// field value (mapped with "value")
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
ArrayList<BeanInner> collection = new ArrayList<>();
BeanInner item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = beanInnerBindMap.parseOnJackson(jacksonParser);
}
collection.add(item);
}
instance.value = collection;
}
break;
case "value2":
// field value2 (mapped with "value2")
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
LinkedList<BeanInner> collection = new LinkedList<>();
BeanInner item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = beanInnerBindMap.parseOnJackson(jacksonParser);
}
collection.add(item);
}
instance.value2 = collection;
}
break;
default:
jacksonParser.skipChildren();
break;
}
}
return instance;
}
use of sqlite.kripton58.BeanInner in project kripton by xcesco.
the class BeanBeanBindMap method serializeOnJacksonAsString.
@Override
public int serializeOnJacksonAsString(BeanBean object, JsonGenerator jacksonSerializer) throws Exception {
jacksonSerializer.writeStartObject();
int fieldCount = 0;
// Serialized Field:
// field id (mapped with "id")
jacksonSerializer.writeStringField("id", PrimitiveUtils.writeLong(object.id));
// field value (mapped with "value")
if (object.value != null) {
fieldCount++;
int n = object.value.size();
BeanInner item;
// write wrapper tag
jacksonSerializer.writeFieldName("value");
if (n > 0) {
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = object.value.get(i);
if (item == null) {
jacksonSerializer.writeString("null");
} else {
if (beanInnerBindMap.serializeOnJacksonAsString(item, jacksonSerializer) == 0) {
jacksonSerializer.writeNullField("value");
}
}
}
jacksonSerializer.writeEndArray();
} else {
jacksonSerializer.writeString("");
}
}
// field value2 (mapped with "value2")
if (object.value2 != null) {
fieldCount++;
int n = object.value2.size();
BeanInner item;
// write wrapper tag
jacksonSerializer.writeFieldName("value2");
if (n > 0) {
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = object.value2.get(i);
if (item == null) {
jacksonSerializer.writeString("null");
} else {
if (beanInnerBindMap.serializeOnJacksonAsString(item, jacksonSerializer) == 0) {
jacksonSerializer.writeNullField("value2");
}
}
}
jacksonSerializer.writeEndArray();
} else {
jacksonSerializer.writeString("");
}
}
jacksonSerializer.writeEndObject();
return fieldCount;
}
use of sqlite.kripton58.BeanInner in project kripton by xcesco.
the class BeanBeanBindMap method serializeOnXml.
/**
* method for xml serialization
*/
@Override
public void serializeOnXml(BeanBean object, XMLSerializer xmlSerializer, int currentEventType) throws Exception {
if (currentEventType == 0) {
xmlSerializer.writeStartElement("beanBean");
}
// Persisted fields:
// field id (mapped with "id")
xmlSerializer.writeStartElement("id");
xmlSerializer.writeLong(object.id);
xmlSerializer.writeEndElement();
// field value (mapped with "value")
if (object.value != null) {
int n = object.value.size();
BeanInner item;
for (int i = 0; i < n; i++) {
item = object.value.get(i);
if (item == null) {
xmlSerializer.writeEmptyElement("value");
} else {
xmlSerializer.writeStartElement("value");
beanInnerBindMap.serializeOnXml(item, xmlSerializer, 2);
xmlSerializer.writeEndElement();
}
}
// to distinguish between first empty element and empty collection, we write an attribute emptyCollection
if (n == 0) {
xmlSerializer.writeStartElement("value");
xmlSerializer.writeAttribute("emptyCollection", "true");
xmlSerializer.writeEndElement();
}
}
// field value2 (mapped with "value2")
if (object.value2 != null) {
int n = object.value2.size();
BeanInner item;
for (int i = 0; i < n; i++) {
item = object.value2.get(i);
if (item == null) {
xmlSerializer.writeEmptyElement("value2");
} else {
xmlSerializer.writeStartElement("value2");
beanInnerBindMap.serializeOnXml(item, xmlSerializer, 2);
xmlSerializer.writeEndElement();
}
}
// to distinguish between first empty element and empty collection, we write an attribute emptyCollection
if (n == 0) {
xmlSerializer.writeStartElement("value2");
xmlSerializer.writeAttribute("emptyCollection", "true");
xmlSerializer.writeEndElement();
}
}
if (currentEventType == 0) {
xmlSerializer.writeEndElement();
}
}
use of sqlite.kripton58.BeanInner in project kripton by xcesco.
the class BeanBeanTable method parseValue2.
/**
* for attribute value2 parsing
*/
public static LinkedList<BeanInner> parseValue2(byte[] input) {
if (input == null) {
return null;
}
KriptonJsonContext context = KriptonBinder.jsonBind();
try (JacksonWrapperParser wrapper = context.createParser(input)) {
JsonParser jacksonParser = wrapper.jacksonParser;
// START_OBJECT
jacksonParser.nextToken();
// value of "element"
jacksonParser.nextValue();
LinkedList<BeanInner> result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
LinkedList<BeanInner> collection = new LinkedList<>();
BeanInner item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = beanInnerBindMap.parseOnJackson(jacksonParser);
}
collection.add(item);
}
result = collection;
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations