Skip to content

Commit

Permalink
Fix FasterXML#397 (alas, no unit tests)
Browse files Browse the repository at this point in the history
# Conflicts:
#	release-notes/VERSION-2.x
  • Loading branch information
cowtowncoder authored and alex-bel-apica committed Sep 4, 2020
1 parent 80becf3 commit 98e0dfe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,16 @@ public JsonToken nextToken() throws IOException
{
JsonToken t = nextToken0();
if (t != null) {
final String loc = _parsingContext.pathAsPointer().toString();
switch (t) {
case FIELD_NAME:
System.out.println("FromXmlParser.nextToken(): JsonToken.FIELD_NAME '"+_parsingContext.getCurrentName()+"'");
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.FIELD_NAME '%s'\n", loc, _parsingContext.getCurrentName());
break;
case VALUE_STRING:
System.out.println("FromXmlParser.nextToken(): JsonToken.VALUE_STRING '"+getText()+"'");
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.VALUE_STRING '%s'\n", loc, getText());
break;
default:
System.out.println("FromXmlParser.nextToken(): "+t);
System.out.printf("FromXmlParser.nextToken() at '%s': %s\n", loc, t);
}
}
return t;
Expand All @@ -486,6 +487,7 @@ public JsonToken nextToken() throws IOException
JsonToken t = _nextToken;
_currToken = t;
_nextToken = null;

switch (t) {
case START_OBJECT:
_parsingContext = _parsingContext.createChildObjectContext(-1, -1);
Expand All @@ -501,7 +503,9 @@ public JsonToken nextToken() throws IOException
_parsingContext.setCurrentName(_xmlTokens.getLocalName());
break;
default: // VALUE_STRING, VALUE_NULL
// should be fine as is?
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index` anyway; not
// used for Object contexts, updated automatically by "createChildXxxContext"
_parsingContext.valueStarted();
}
return t;
}
Expand Down Expand Up @@ -564,6 +568,8 @@ public JsonToken nextToken() throws IOException
}
// 07-Sep-2019, tatu: for [dataformat-xml#353], must NOT return second null
if (_currToken != JsonToken.VALUE_NULL) {
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
_parsingContext.valueStarted();
return (_currToken = JsonToken.VALUE_NULL);
}
}
Expand All @@ -584,6 +590,8 @@ public JsonToken nextToken() throws IOException
return (_currToken = JsonToken.FIELD_NAME);
case XmlTokenStream.XML_ATTRIBUTE_VALUE:
_currText = _xmlTokens.getText();
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
_parsingContext.valueStarted();
return (_currToken = JsonToken.VALUE_STRING);
case XmlTokenStream.XML_TEXT:
_currText = _xmlTokens.getText();
Expand Down Expand Up @@ -666,6 +674,8 @@ public String nextTextValue() throws IOException

// expected case; yes, got a String
if (t == JsonToken.VALUE_STRING) {
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
_parsingContext.valueStarted();
return _currText;
}
_updateState(t);
Expand Down Expand Up @@ -715,6 +725,8 @@ public String nextTextValue() throws IOException
// NOTE: this is different from nextToken() -- produce "", NOT null
_mayBeLeaf = false;
_currToken = JsonToken.VALUE_STRING;
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
_parsingContext.valueStarted();
return (_currText = "");
}
_currToken = _parsingContext.inArray() ? JsonToken.END_ARRAY : JsonToken.END_OBJECT;
Expand All @@ -735,6 +747,8 @@ public String nextTextValue() throws IOException
break;
case XmlTokenStream.XML_ATTRIBUTE_VALUE:
_currToken = JsonToken.VALUE_STRING;
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
_parsingContext.valueStarted();
return (_currText = _xmlTokens.getText());
case XmlTokenStream.XML_TEXT:
_currText = _xmlTokens.getText();
Expand All @@ -748,6 +762,8 @@ public String nextTextValue() throws IOException
}
// NOTE: this is different from nextToken() -- NO work-around
// for otherwise empty List/array
// 13-May-2020, tatu: [dataformat-xml#397]: advance `index`
_parsingContext.valueStarted();
_currToken = JsonToken.VALUE_STRING;
return _currText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static XmlReadContext createRootContext() {

public final XmlReadContext createChildArrayContext(int lineNr, int colNr)
{
++_index; // not needed for Object, but does not hurt so no need to check curr type
XmlReadContext ctxt = _child;
if (ctxt == null) {
_child = ctxt = new XmlReadContext(this, TYPE_ARRAY, lineNr, colNr);
Expand All @@ -116,6 +117,7 @@ public final XmlReadContext createChildArrayContext(int lineNr, int colNr)

public final XmlReadContext createChildObjectContext(int lineNr, int colNr)
{
++_index; // not needed for Object, but does not hurt so no need to check curr type
XmlReadContext ctxt = _child;
if (ctxt == null) {
_child = ctxt = new XmlReadContext(this, TYPE_OBJECT, lineNr, colNr);
Expand All @@ -127,7 +129,7 @@ public final XmlReadContext createChildObjectContext(int lineNr, int colNr)

/*
/**********************************************************
/* Abstract method implementation
/* Abstract method implementation, overrides
/**********************************************************
*/

Expand All @@ -140,18 +142,16 @@ public final XmlReadContext createChildObjectContext(int lineNr, int colNr)
@Override
public final XmlReadContext getParent() { return _parent; }

/*
/**********************************************************
/* State changes
/**********************************************************
/**
* @return Location pointing to the point where the context
* start marker was found
*/
@Override
public final JsonLocation getStartLocation(Object srcRef) {
// We don't keep track of offsets at this level (only reader does)
long totalChars = -1L;

public final boolean expectComma() {
throw new UnsupportedOperationException();
}

public void setCurrentName(String name) {
_currentName = name;
return new JsonLocation(srcRef, totalChars, _lineNr, _columnNr);
}

/*
Expand All @@ -161,15 +161,17 @@ public void setCurrentName(String name) {
*/

/**
* @return Location pointing to the point where the context
* start marker was found
* Method called to mark start of new value, mostly to update `index`
* for Array and Root contexts.
*
* @since 2.12
*/
@Override
public final JsonLocation getStartLocation(Object srcRef) {
// We don't keep track of offsets at this level (only reader does)
long totalChars = -1L;
public final void valueStarted() {
++_index;
}

return new JsonLocation(srcRef, totalChars, _lineNr, _columnNr);
public void setCurrentName(String name) {
_currentName = name;
}

public void setNamesToWrap(Set<String> namesToWrap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.*;

import com.fasterxml.jackson.annotation.JsonInclude;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
Expand All @@ -12,20 +10,6 @@

public class ListDeser393Test extends XmlTestBase
{
@JacksonXmlRootElement(localName = "result")
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Value393 {
private Prices393 prices = new Prices393();

public void setPrices(Prices393 prices) {
this.prices = prices;
}

public Prices393 getPrices() {
return this.prices;
}
}

@JacksonXmlRootElement(localName = "prices")
static class Prices393 {
private List<Price393> price = new ArrayList<Price393>();
Expand Down

0 comments on commit 98e0dfe

Please sign in to comment.