More work on trying to call JsonParser.nextTextValue() for String-valued JSON arrays, to help with XML processing
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/PrimitiveArrayDeserializers.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/PrimitiveArrayDeserializers.java
index 7ecdd90..d83d7cf 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/PrimitiveArrayDeserializers.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/PrimitiveArrayDeserializers.java
@@ -52,8 +52,7 @@
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
- TypeDeserializer typeDeserializer)
- throws IOException, JsonProcessingException
+ TypeDeserializer typeDeserializer) throws IOException
{
/* Should there be separate handling for base64 stuff?
* for now this should be enough:
@@ -76,8 +75,7 @@
public CharDeser() { super(char[].class); }
@Override
- public char[] deserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ public char[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
/* Won't take arrays, must get a String (could also
* convert other tokens to Strings... but let's not bother
@@ -170,8 +168,7 @@
return builder.completeAndClearBuffer(chunk, ix);
}
- private final boolean[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ private final boolean[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
@@ -200,8 +197,7 @@
public ByteDeser() { super(byte[].class); }
@Override
- public byte[] deserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ public byte[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
@@ -250,8 +246,7 @@
return builder.completeAndClearBuffer(chunk, ix);
}
- private final byte[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ private final byte[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
@@ -288,8 +283,7 @@
public ShortDeser() { super(short[].class); }
@Override
- public short[] deserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ public short[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
@@ -313,8 +307,7 @@
return builder.completeAndClearBuffer(chunk, ix);
}
- private final short[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ private final short[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
@@ -341,8 +334,7 @@
public IntDeser() { super(int[].class); }
@Override
- public int[] deserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ public int[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
@@ -367,8 +359,7 @@
return builder.completeAndClearBuffer(chunk, ix);
}
- private final int[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ private final int[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
@@ -395,8 +386,7 @@
public LongDeser() { super(long[].class); }
@Override
- public long[] deserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ public long[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
@@ -420,8 +410,7 @@
return builder.completeAndClearBuffer(chunk, ix);
}
- private final long[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ private final long[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
@@ -498,8 +487,7 @@
public DoubleDeser() { super(double[].class); }
@Override
- public double[] deserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ public double[] deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt);
@@ -523,8 +511,7 @@
return builder.completeAndClearBuffer(chunk, ix);
}
- private final double[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException
+ private final double[] handleNonArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringArrayDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringArrayDeserializer.java
index 5028e78..3850b42 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringArrayDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringArrayDeserializer.java
@@ -91,12 +91,25 @@
final JsonDeserializer<String> deser = _elementDeserializer;
int ix = 0;
- JsonToken t;
try {
- while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
- // Ok: no need to convert Strings, but must recognize nulls
- String value = (t == JsonToken.VALUE_NULL) ? deser.getNullValue() : deser.deserialize(jp, ctxt);
+ while (true) {
+ /* 30-Dec-2014, tatu: This may look odd, but let's actually call method
+ * that suggest we are expecting a String; this helps with some formats,
+ * notably XML. Note, however, that while we can get String, we can't
+ * assume that's what we use due to custom deserializer
+ */
+ String value;
+ if (jp.nextTextValue() == null) {
+ JsonToken t = jp.getCurrentToken();
+ if (t == JsonToken.END_ARRAY) {
+ break;
+ }
+ // Ok: no need to convert Strings, but must recognize nulls
+ value = (t == JsonToken.VALUE_NULL) ? deser.getNullValue() : deser.deserialize(jp, ctxt);
+ } else {
+ value = deser.deserialize(jp, ctxt);
+ }
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java
index 6af3b49..143070d 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringCollectionDeserializer.java
@@ -199,12 +199,20 @@
private Collection<String> deserializeUsingCustom(JsonParser jp, DeserializationContext ctxt,
Collection<String> result, final JsonDeserializer<String> deser) throws IOException
{
- JsonToken t;
- while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
+ while (true) {
+ /* 30-Dec-2014, tatu: This may look odd, but let's actually call method
+ * that suggest we are expecting a String; this helps with some formats,
+ * notably XML. Note, however, that while we can get String, we can't
+ * assume that's what we use due to custom deserializer
+ */
String value;
-
- if (t == JsonToken.VALUE_NULL) {
- value = deser.getNullValue();
+ if (jp.nextTextValue() == null) {
+ JsonToken t = jp.getCurrentToken();
+ if (t == JsonToken.END_ARRAY) {
+ break;
+ }
+ // Ok: no need to convert Strings, but must recognize nulls
+ value = (t == JsonToken.VALUE_NULL) ? deser.getNullValue() : deser.deserialize(jp, ctxt);
} else {
value = deser.deserialize(jp, ctxt);
}
@@ -220,7 +228,7 @@
}
/**
- * Helper method called when current token is no START_ARRAY. Will either
+ * Helper method called when current token is not START_ARRAY. Will either
* throw an exception, or try to handle value as if member of implicit
* array, depending on configuration.
*/