Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public Class<?> valueType() {
/**********************************************************************
*/

/**
* Helper method for getting description of type of values this reader
* produces from input: used for example in exception messages.
*
* @since 2.20
*/
protected String _valueTypeDesc() {
return _valueType.getCanonicalName();
}

/**
* Helper method for getting description of the token parser currently points to,
* for use in descriptions and exception messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ public void writeField(String fieldName, Object value, int type) throws IOExcept
case SER_BOOLEAN_ARRAY:
writeBooleanArrayField(fieldName, (boolean[]) value);
return;
case SER_SHORT_ARRAY:
writeShortArrayField(fieldName, (short[]) value);
return;
case SER_FLOAT_ARRAY:
writeFloatArrayField(fieldName, (float[]) value);
return;
case SER_DOUBLE_ARRAY:
writeDoubleArrayField(fieldName, (double[]) value);
return;
case SER_TREE_NODE:
writeTreeNodeField(fieldName, (TreeNode) value);
return;
Expand Down Expand Up @@ -319,6 +328,15 @@ protected void _writeValue(Object value, int type) throws IOException
case SER_BOOLEAN_ARRAY:
writeBooleanArrayValue((boolean[]) value);
return;
case SER_SHORT_ARRAY:
writeShortArrayValue((short[]) value);
return;
case SER_FLOAT_ARRAY:
writeFloatArrayValue((float[]) value);
return;
case SER_DOUBLE_ARRAY:
writeDoubleArrayValue((double[]) value);
return;
case SER_TREE_NODE:
writeTreeNodeValue((TreeNode) value);
return;
Expand Down Expand Up @@ -427,7 +445,11 @@ protected void _writeValue(Object value, int type) throws IOException

protected void writeCollectionValue(Collection<?> v) throws IOException
{
_generator.writeStartArray();
if (v instanceof RandomAccess) {
_generator.writeStartArray(v, v.size());
} else {
_generator.writeStartArray(v);
}
for (Object ob : v) {
writeValue(ob);
}
Expand All @@ -442,7 +464,7 @@ protected void writeCollectionField(String fieldName, Collection<?> v) throws IO

protected void writeIterableValue(Iterable<?> v) throws IOException
{
_generator.writeStartArray();
_generator.writeStartArray(v);
for (Object ob : v) {
writeValue(ob);
}
Expand All @@ -457,7 +479,11 @@ protected void writeIterableField(String fieldName, Iterable<?> v) throws IOExce

protected void writeListValue(List<?> list) throws IOException
{
_generator.writeStartArray();
if (list instanceof RandomAccess) {
_generator.writeStartArray(list, list.size());
} else {
_generator.writeStartArray(list);
}
for (int i = 0, len = list.size(); i < len; ++i) {
Object value = list.get(i);
if (value == null) {
Expand All @@ -477,7 +503,7 @@ protected void writeListField(String fieldName, List<?> v) throws IOException

protected void writeMapValue(Map<?,?> v) throws IOException
{
_generator.writeStartObject();
_generator.writeStartObject(v, v.size());
if (!v.isEmpty()) {
for (Map.Entry<?,?> entry : v.entrySet()) {
String key = keyToString(entry.getKey());
Expand All @@ -504,8 +530,9 @@ protected void writeMapField(String fieldName, Map<?,?> v) throws IOException
}

protected void writeObjectArrayValue(Object[] v) throws IOException {
_generator.writeStartArray();
for (int i = 0, len = v.length; i < len; ++i) {
final int len = v.length;
_generator.writeStartArray(v, len);
for (int i = 0; i < len; ++i) {
writeValue(v[i]);
}
_generator.writeEndArray();
Expand All @@ -517,11 +544,7 @@ protected void writeObjectArrayField(String fieldName, Object[] v) throws IOExce
}

protected void writeIntArrayValue(int[] v) throws IOException {
_generator.writeStartArray();
for (int i = 0, len = v.length; i < len; ++i) {
_generator.writeNumber(v[i]);
}
_generator.writeEndArray();
_generator.writeArray(v, 0, v.length);
}

protected void writeIntArrayField(String fieldName, int[] v) throws IOException {
Expand All @@ -530,11 +553,7 @@ protected void writeIntArrayField(String fieldName, int[] v) throws IOException
}

protected void writeLongArrayValue(long[] v) throws IOException {
_generator.writeStartArray();
for (int i = 0, len = v.length; i < len; ++i) {
_generator.writeNumber(v[i]);
}
_generator.writeEndArray();
_generator.writeArray(v, 0, v.length);
}

protected void writeLongArrayField(String fieldName, long[] v) throws IOException {
Expand All @@ -543,7 +562,7 @@ protected void writeLongArrayField(String fieldName, long[] v) throws IOExceptio
}

protected void writeBooleanArrayValue(boolean[] v) throws IOException {
_generator.writeStartArray();
_generator.writeStartArray(v, v.length);
for (int i = 0, len = v.length; i < len; ++i) {
_generator.writeBoolean(v[i]);
}
Expand All @@ -555,6 +574,41 @@ protected void writeBooleanArrayField(String fieldName, boolean[] v) throws IOEx
writeBooleanArrayValue(v);
}

protected void writeShortArrayValue(short[] v) throws IOException {
_generator.writeStartArray(v, v.length);
for (int i = 0, len = v.length; i < len; ++i) {
_generator.writeNumber(v[i]);
}
_generator.writeEndArray();
}

protected void writeShortArrayField(String fieldName, short[] v) throws IOException {
_generator.writeFieldName(fieldName);
writeShortArrayValue(v);
}

protected void writeFloatArrayValue(float[] v) throws IOException {
_generator.writeStartArray(v, v.length);
for (int i = 0, len = v.length; i < len; ++i) {
_generator.writeNumber(v[i]);
}
_generator.writeEndArray();
}

protected void writeFloatArrayField(String fieldName, float[] v) throws IOException {
_generator.writeFieldName(fieldName);
writeFloatArrayValue(v);
}

protected void writeDoubleArrayValue(double[] v) throws IOException {
_generator.writeArray(v, 0, v.length);
}

protected void writeDoubleArrayField(String fieldName, double[] v) throws IOException {
_generator.writeFieldName(fieldName);
writeDoubleArrayValue(v);
}

protected void writeTreeNodeValue(TreeNode v) throws IOException {
if (_treeCodec == null) {
throw new JSONObjectException("No `TreeCodec` configured: can not serialize `TreeNode` values");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ public Object read(JSONReader reader, JsonParser p) throws IOException
return _readIntArray(p);
case SER_LONG_ARRAY:
return _readLongArray(p);
//case SER_BOOLEAN_ARRAY:
// TODO:


// Not yet supported:
case SER_BOOLEAN_ARRAY:
case SER_SHORT_ARRAY:
case SER_FLOAT_ARRAY:
case SER_DOUBLE_ARRAY:
throw JSONObjectException.from(p,
"Deserialization of `"+_valueTypeDesc()+"` not yet supported");
case SER_TREE_NODE:
return reader.readTree();

Expand Down Expand Up @@ -271,7 +276,7 @@ public Object read(JSONReader reader, JsonParser p) throws IOException
}

throw JSONObjectException.from(p,
"Can not create a `"+_valueType.getName()+"` instance out of "+_tokenDesc(p));
"Can not create a `"+_valueTypeDesc()+"` instance out of "+_tokenDesc(p));
}

/*
Expand Down Expand Up @@ -374,6 +379,6 @@ protected long _fetchLong(JsonParser p) throws IOException
return p.getLongValue();
}
throw JSONObjectException.from(p, "Can not get long numeric value from JSON (to construct "
+_valueType.getName()+") from "+_tokenDesc(p, t));
+_valueTypeDesc()+") from "+_tokenDesc(p, t));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,69 +58,72 @@ public abstract class ValueLocatorBase
*/
public final static int SER_OBJECT_ARRAY = 4;

public final static int SER_INT_ARRAY = 5;
public final static int SER_LONG_ARRAY = 6;
public final static int SER_BOOLEAN_ARRAY = 7;
public final static int SER_SHORT_ARRAY = 5; // since 2.20
public final static int SER_INT_ARRAY = 6;
public final static int SER_LONG_ARRAY = 7;
public final static int SER_FLOAT_ARRAY = 8; // since 2.20
public final static int SER_DOUBLE_ARRAY = 9; // since 2.20
public final static int SER_BOOLEAN_ARRAY = 10;

/**
* An implementation of {@link com.fasterxml.jackson.core.TreeNode}
*/
public final static int SER_TREE_NODE = 8;
public final static int SER_TREE_NODE = 11;

// // // String(-like) types

public final static int SER_STRING = 9;
public final static int SER_CHARACTER_SEQUENCE = 10;
public final static int SER_CHAR_ARRAY = 11;
public final static int SER_BYTE_ARRAY = 12;
public final static int SER_STRING = 12;
public final static int SER_CHARACTER_SEQUENCE = 13;
public final static int SER_CHAR_ARRAY = 14;
public final static int SER_BYTE_ARRAY = 15;

// // // Numbers

public final static int SER_NUMBER_BYTE = 13;
public final static int SER_NUMBER_BYTE = 16;

public final static int SER_NUMBER_SHORT = 14;
public final static int SER_NUMBER_SHORT = 17;

public final static int SER_NUMBER_INTEGER = 15;
public final static int SER_NUMBER_INTEGER_WRAPPER = 16;
public final static int SER_NUMBER_INTEGER = 18;
public final static int SER_NUMBER_INTEGER_WRAPPER = 19;

public final static int SER_NUMBER_LONG = 17;
public final static int SER_NUMBER_LONG_WRAPPER = 18;
public final static int SER_NUMBER_LONG = 20;
public final static int SER_NUMBER_LONG_WRAPPER = 21;

public final static int SER_NUMBER_FLOAT = 19;
public final static int SER_NUMBER_FLOAT_WRAPPER = 20;
public final static int SER_NUMBER_FLOAT = 22;
public final static int SER_NUMBER_FLOAT_WRAPPER = 23;

public final static int SER_NUMBER_DOUBLE = 21;
public final static int SER_NUMBER_DOUBLE_WRAPPER = 22;
public final static int SER_NUMBER_DOUBLE = 24;
public final static int SER_NUMBER_DOUBLE_WRAPPER = 25;

public final static int SER_NUMBER_BIG_INTEGER = 23;
public final static int SER_NUMBER_BIG_INTEGER = 26;

public final static int SER_NUMBER_BIG_DECIMAL = 24;
public final static int SER_NUMBER_BIG_DECIMAL = 27;

// // // Other specific scalar types

public final static int SER_BOOLEAN = 25;
public final static int SER_BOOLEAN_WRAPPER = 26;
public final static int SER_CHAR = 27;
public final static int SER_BOOLEAN = 28;
public final static int SER_BOOLEAN_WRAPPER = 29;
public final static int SER_CHAR = 30;

public final static int SER_ENUM = 28;
public final static int SER_ENUM = 31;

public final static int SER_DATE = 29;
public final static int SER_CALENDAR = 30;
public final static int SER_DATE = 32;
public final static int SER_CALENDAR = 33;

public final static int SER_CLASS = 31;
public final static int SER_FILE = 32;
public final static int SER_UUID = 33;
public final static int SER_URL = 34;
public final static int SER_URI = 35;
public final static int SER_PATH = 36; // since 2.17
public final static int SER_CLASS = 34;
public final static int SER_FILE = 35;
public final static int SER_UUID = 36;
public final static int SER_URL = 37;
public final static int SER_URI = 38;
public final static int SER_PATH = 39; // since 2.17

// // // Iterate-able types

/**
* Anything that implements {@link java.lang.Iterable}, but not
* {@link java.util.Collection}.
*/
public final static int SER_ITERABLE = 37;
public final static int SER_ITERABLE = 40;

/*
/**********************************************************************
Expand Down Expand Up @@ -159,6 +162,15 @@ protected int _findSimpleType(Class<?> raw, boolean forSer)
if (raw == boolean[].class) {
return SER_BOOLEAN_ARRAY;
}
if (raw == short[].class) {
return SER_SHORT_ARRAY;
}
if (raw == float[].class) {
return SER_FLOAT_ARRAY;
}
if (raw == double[].class) {
return SER_DOUBLE_ARRAY;
}
// Hmmh. Could support all types; add as/when needed
return SER_UNKNOWN;
}
Expand Down
Loading