net.vvakame.zaim4j.AccountItemGen Maven / Gradle / Ivy
package net.vvakame.zaim4j;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import net.vvakame.util.jsonpullparser.JsonFormatException;
import net.vvakame.util.jsonpullparser.JsonPullParser;
import net.vvakame.util.jsonpullparser.JsonPullParser.State;
import net.vvakame.util.jsonpullparser.util.JsonUtil;
import net.vvakame.util.jsonpullparser.util.OnJsonObjectAddListener;
/**
* Parses JSON-formatted data into {@link AccountItem} with {@link JsonPullParser}.
* NB: This class is auto-generated by APT; please do not edit by hand.
*/
class AccountItemGen {
/**
* Attempts to parse the given data as {@link List} of {@link AccountItem}.
* @param json JSON-formatted data
* @return {@link List} of {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static List getList(String json) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(json);
return getList(parser, null);
}
/**
* Attempts to parse the given data as {@link List} of {@link AccountItem}.
* Accepts {@link OnJsonObjectAddListener}; allows you to peek various intermittent instances as parsing goes.
*
* @param json JSON-formatted data
* @param listener {@link OnJsonObjectAddListener} to notify
* @return {@link List} of {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static List getList(String json, OnJsonObjectAddListener listener) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(json);
return getList(parser, listener);
}
/**
* Attempts to parse the given data as {@link List} of {@link AccountItem}.
*
* @param stream JSON-formatted data
* @return {@link List} of {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static List getList(InputStream stream) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(stream);
return getList(parser, null);
}
/**
* Attempts to parse the given data as {@link List} of {@link AccountItem}.
* Accepts {@link OnJsonObjectAddListener}; allows you to peek various intermittent instances as parsing goes.
*
* @param stream JSON-formatted data
* @param listener {@link OnJsonObjectAddListener} to notify
* @return {@link List} of {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static List getList(InputStream stream, OnJsonObjectAddListener listener) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(stream);
return getList(parser, listener);
}
/**
* Attempts to parse the given data as {@link List} of {@link AccountItem}.
*
* @param parser {@link JsonPullParser} with some JSON-formatted data
* @return {@link List} of {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static List getList(JsonPullParser parser) throws IOException, JsonFormatException {
return getList(parser, null);
}
/**
* Attempts to parse the given data as {@link List} of {@link AccountItem}.
* Accepts {@link OnJsonObjectAddListener}; allows you to peek various intermittent instances as parsing goes.
*
* @param parser {@link JsonPullParser} with some JSON-formatted data
* @param listener {@link OnJsonObjectAddListener} to notify
* @return {@link List} of {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static List getList(JsonPullParser parser, OnJsonObjectAddListener listener) throws IOException, JsonFormatException {
List list = new ArrayList();
State eventType = parser.getEventType();
if (eventType == State.VALUE_NULL) {
if (listener != null) {
listener.onAdd(null);
}
return null;
}
if (eventType != State.START_ARRAY) {
if(eventType == State.START_HASH){
throw new JsonFormatException("not started '['!, Do you want the json hash?");
} else {
throw new JsonFormatException("not started '['!");
}
}
while (parser.lookAhead() != State.END_ARRAY) {
AccountItem tmp = get(parser, listener);
list.add(tmp);
}
parser.getEventType();
return list;
}
/**
* Attempts to parse the given data as {@link AccountItem}.
*
* @param json JSON-formatted data
* @return {{@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static AccountItem get(String json) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(json);
return get(parser, null);
}
/**
* Attempts to parse the given data as {@link AccountItem}.
* Accepts {@link OnJsonObjectAddListener}; allows you to peek various intermittent instances as parsing goes.
*
* @param json JSON-formatted data
* @param listener {@link OnJsonObjectAddListener} to notify
* @return {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static AccountItem get(String json, OnJsonObjectAddListener listener) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(json);
return get(parser, listener);
}
/**
* Attempts to parse the given data as {@link AccountItem}.
*
* @param stream JSON-formatted data
* @return {{@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static AccountItem get(InputStream stream) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(stream);
return get(parser, null);
}
/**
* Attempts to parse the given data as {@link AccountItem}.
* Accepts {@link OnJsonObjectAddListener}; allows you to peek various intermittent instances as parsing goes.
*
* @param stream JSON-formatted data
* @param listener {@link OnJsonObjectAddListener} to notify
* @return {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static AccountItem get(InputStream stream, OnJsonObjectAddListener listener) throws IOException, JsonFormatException {
JsonPullParser parser = JsonPullParser.newParser(stream);
return get(parser, listener);
}
/**
* Attempts to parse the given data as {@link AccountItem}.
*
* @param parser {@link JsonPullParser} with some JSON-formatted data
* @return {{@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static AccountItem get(JsonPullParser parser) throws IOException, JsonFormatException {
return get(parser, null);
}
/**
* Attempts to parse the given data as {@link AccountItem}.
* Accepts {@link OnJsonObjectAddListener}; allows you to peek various intermittent instances as parsing goes.
*
* @param parser {@link JsonPullParser} with some JSON-formatted data
* @param listener {@link OnJsonObjectAddListener} to notify
* @return {@link AccountItem}
* @throws IOException if an I/O error occurs.
* @throws IllegalStateException @SaveOrigin is enabled while {@link JsonPullParser#setLogEnable()} is not called yet.
* @throws JsonFormatException The given data is malformed, or its type is unexpected
*/
public static AccountItem get(JsonPullParser parser, OnJsonObjectAddListener listener) throws IOException, IllegalStateException, JsonFormatException {
AccountItem obj = new AccountItem();
State eventType = parser.getEventType();
if (eventType == State.VALUE_NULL) {
if (listener != null) {
listener.onAdd(null);
}
return null;
}
if (eventType != State.START_HASH) {
if (eventType == State.START_ARRAY) {
throw new JsonFormatException("not started '{'! Do you want the json array?");
} else {
throw new JsonFormatException("not started '{'!");
}
}
while ((eventType = parser.getEventType()) != State.END_HASH) {
if (eventType != State.KEY) {
throw new JsonFormatException("expect KEY. we got unexpected value. " + eventType);
}
String key = parser.getValueString();
if(parseValue(parser, listener, key, obj)){
continue;
} else {
throw new JsonFormatException("unsupported key. key=" + key);
}
}
if (listener != null) {
listener.onAdd(obj);
}
return obj;
}
/**
* *** Internal use only; please do not call directly. ***
* *** Public access granted only to allow reusing from other packages. ***
*
* @param parser {@link JsonPullParser} in action
* @param listener {@link OnJsonObjectAddListener} to listen new instance creations
* @param key JSON key being parsed
* @param obj {@link AccountItem} (and like) being rebuilt
* @return True if the given key is parsed successfully, false otherwise
* @throws IOException if an I/O error occurs.
* @throws JsonFormatException Data is malformed, or its type is unexpected
* @author vvakame
*/
public static boolean parseValue(JsonPullParser parser, OnJsonObjectAddListener listener, String key, AccountItem obj) throws IOException, JsonFormatException {
if ("id".equals(key)) {
parser.getEventType();
obj.setId(parser.getValueLong());
} else
if ("name".equals(key)) {
parser.getEventType();
obj.setName(parser.getValueString());
} else
if ("color".equals(key)) {
parser.getEventType();
obj.setColor(parser.getValueString());
} else
if ("icon_url".equals(key)) {
parser.getEventType();
obj.setIconUrl(parser.getValueString());
} else
if ("description".equals(key)) {
parser.getEventType();
obj.setDescription(parser.getValueString());
} else
if ("currency_code".equals(key)) {
if(State.VALUE_NULL.equals(parser.getEventType())){
obj.setCurrencyCode(null);
} else {
obj.setCurrencyCode(Enum.valueOf(net.vvakame.zaim4j.CurrencyCode.class, parser.getValueString()));
}
} else
if ("sort".equals(key)) {
parser.getEventType();
obj.setSort(parser.getValueLong());
} else
if ("modified".equals(key)) {
parser.getEventType();
obj.setModified(parser.getValueString());
} else
if ("active".equals(key)) {
net.vvakame.zaim4j.Active.ActiveConverter converter = net.vvakame.zaim4j.Active.ActiveConverter.getInstance();
net.vvakame.zaim4j.Active tmp = converter.parse(parser, listener);
obj.setActive(tmp);
} else {
return false;
}
return true;
}
/**
* Encodes the given {@link List} of {@link AccountItem} into the JSON format, and appends it into the given stream using {@link JsonPullParser#DEFAULT_CHARSET}.
* This method is an alias of {@link #encodeListNullToBlank(Writer, List)}.
*
* @param out {@link OutputStream} to be written
* @param list {@link List} of {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encodeList(OutputStream out, List extends AccountItem> list) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(out, JsonPullParser.DEFAULT_CHARSET);
encodeListNullToBlank(writer, list);
}
/**
* Encodes the given {@link List} of {@link AccountItem} into the JSON format, and writes it using the given writer.
* This method is an alias of {@link #encodeListNullToBlank(Writer, List)}.
*
* @param writer {@link Writer} to be used for writing value
* @param list {@link List} of {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encodeList(Writer writer, List extends AccountItem> list) throws IOException {
encodeListNullToBlank(writer, list);
}
/**
* Encodes the given {@link List} of {@link AccountItem} into the JSON format, and writes it using the given writer.
* Writes "[]" if null is given.
*
* @param writer {@link Writer} to be used for writing value
* @param list {@link List} of {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encodeListNullToBlank(Writer writer, List extends AccountItem> list) throws IOException {
if (list == null) {
writer.write("[]");
writer.flush();
return;
}
encodeListNullToNull(writer, list);
}
/**
* Encodes the given {@link List} of {@link AccountItem} into the JSON format, and writes it using the given writer.
* Writes "null" if null is given.
*
* @param writer {@link Writer} to be used for writing value
* @param list {@link List} of {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encodeListNullToNull(Writer writer, List extends AccountItem> list) throws IOException {
if (list == null) {
writer.write("null");
writer.flush();
return;
}
JsonUtil.startArray(writer);
int size = list.size();
for (int i = 0; i < size; i++) {
encodeNullToNull(writer, list.get(i));
if (i + 1 < size) {
JsonUtil.addSeparator(writer);
}
}
JsonUtil.endArray(writer);
writer.flush();
}
/**
* Encodes the given {@link AccountItem} into the JSON format, and appends it into the given stream using {@link JsonPullParser#DEFAULT_CHARSET}.
* This method is an alias of {@link #encodeNullToBlank(Writer, AccountItem)}.
*
* @param out {@link OutputStream} to be written
* @param obj {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encode(OutputStream out, AccountItem obj) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(out, JsonPullParser.DEFAULT_CHARSET);
encodeNullToBlank(writer, obj);
}
/**
* Encodes the given {@link AccountItem} into the JSON format, and writes it using the given writer.
* This method is an alias of {@link #encodeNullToBlank(Writer, AccountItem)}.
*
* @param writer {@link Writer} to be used for writing value
* @param obj {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encode(Writer writer, AccountItem obj) throws IOException {
encodeNullToBlank(writer, obj);
}
/**
* Encodes the given {@link AccountItem} into the JSON format, and writes it using the given writer.
* Writes "{}" if null is given.
*
* @param writer {@link Writer} to be used for writing value
* @param obj {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encodeNullToBlank(Writer writer, AccountItem obj) throws IOException {
if (obj == null) {
writer.write("{}");
writer.flush();
return;
}
encodeNullToNull(writer, obj);
}
/**
* Encodes the given {@link AccountItem} into the JSON format, and writes it using the given writer.
* Writes "null" if null is given.
*
* @param writer {@link Writer} to be used for writing value
* @param obj {@link AccountItem} to be encoded
* @throws IOException if an I/O error occurs.
*/
public static void encodeNullToNull(Writer writer, AccountItem obj) throws IOException {
if (obj == null) {
writer.write("null");
return;
}
JsonUtil.startHash(writer);
encodeValue(writer, obj);
JsonUtil.endHash(writer);
writer.flush();
}
/**
* *** Internal use only; please do not call directly. ***
* *** Public access granted only to allow reusing from other packages. ***
*
* @param writer {@link Writer}
* @param obj value
* @return is write some value
* @throws IOException if an I/O error occurs.
* @author vvakame
*/
public static boolean encodeValue(Writer writer, AccountItem obj) throws IOException {
JsonUtil.putKey(writer, "id");
JsonUtil.put(writer, obj.getId());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "name");
JsonUtil.put(writer, obj.getName());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "color");
JsonUtil.put(writer, obj.getColor());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "icon_url");
JsonUtil.put(writer, obj.getIconUrl());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "description");
JsonUtil.put(writer, obj.getDescription());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "currency_code");
JsonUtil.put(writer, obj.getCurrencyCode());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "sort");
JsonUtil.put(writer, obj.getSort());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "modified");
JsonUtil.put(writer, obj.getModified());
JsonUtil.addSeparator(writer);
JsonUtil.putKey(writer, "active");
net.vvakame.zaim4j.Active.ActiveConverter.getInstance().encodeNullToNull(writer, obj.getActive());
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy