com.fasterxml.jackson.jr.ob.comp.CollectionComposer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-jr-objects Show documentation
Show all versions of jackson-jr-objects Show documentation
Simple data-binding that builds directly on jackson-core (streaming),
has no other dependencies, and provides additional builder-style content generator
The newest version!
package com.fasterxml.jackson.jr.ob.comp;
import java.util.*;
import com.fasterxml.jackson.core.JsonGenerator;
public class CollectionComposer>
extends ComposerBase
{
protected final PARENT _parent;
protected C _collection;
public CollectionComposer(PARENT parent) {
super();
_parent = parent;
}
public CollectionComposer(C coll) {
super();
_parent = null;
_collection = coll;
}
public static > CollectionComposer,T>
rootComposer(T coll) {
return new CollectionComposer(coll);
}
/*
/**********************************************************************
/* Abstract method impls
/**********************************************************************
*/
@Override
public void flush() { }
@Override
protected CollectionComposer _start() {
if (_collection == null) {
_collection = constructCollection();
}
return this;
}
@Override
protected C _finish() {
if (_open) {
_open = false;
}
return _collection;
}
/*
/**********************************************************************
/* Compose methods, structures
/**********************************************************************
*/
public CollectionComposer,?> startArray()
{
_closeChild();
CollectionComposer,?> child = _startCollection(this);
_collection.add(child._collection);
return child;
}
public MapComposer> startObject()
{
_closeChild();
MapComposer> child = _startMap(this);
_collection.add(child._map);
return child;
}
public C finish() {
return _finish();
}
/*
/**********************************************************************
/* Compose methods, scalars, number
/**********************************************************************
*/
public CollectionComposer add(int value)
{
_collection.add(Integer.valueOf(value));
return this;
}
public CollectionComposer add(long value)
{
_collection.add(Long.valueOf(value));
return this;
}
public CollectionComposer add(double value)
{
_collection.add(Double.valueOf(value));
return this;
}
/*
/**********************************************************************
/* Compose methods, scalars, textual / binary
/**********************************************************************
*/
public CollectionComposer add(String value)
{
_collection.add(value);
return this;
}
public CollectionComposer add(CharSequence value)
{
String str = (value == null) ? null : value.toString();
_collection.add(str);
return this;
}
/*
/**********************************************************************
/* Compose methods, scalars, other
/**********************************************************************
*/
public CollectionComposer addNull()
{
_collection.add(null);
return this;
}
public CollectionComposer add(boolean value)
{
_collection.add(value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
/**
* Method used to add Java Object ("POJO") into sequence being
* composed: this requires that the underlying {@link JsonGenerator}
* has a properly configured {@link com.fasterxml.jackson.core.ObjectCodec}
* to use for serializer object.
*/
public CollectionComposer addObject(Object pojo)
{
_collection.add(pojo);
return this;
}
/*
/**********************************************************************
/* Compose methods, structures
/**********************************************************************
*/
public PARENT end()
{
_closeChild();
if (_open) {
_open = false;
_parent._childClosed();
}
return _parent;
}
/*
/**********************************************************************
/* Overridable helper methods
/**********************************************************************
*/
@SuppressWarnings("unchecked")
protected C constructCollection() {
return (C) new ArrayList
© 2015 - 2024 Weber Informatics LLC | Privacy Policy