Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored and pjankovsky committed Jun 25, 2019
1 parent c804727 commit cb7ea05
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Modules:
(reported by jflefebvre06@github)
#122: (csv) `readValues(null)` causes infinite loop
(reported by andyeko@github)
#123: (yaml) YAML Anchor, reference fails with simple example

2.9.8 (15-Dec-2018)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ public JsonToken nextToken() throws IOException
return (_currToken = null);
}
_lastEvent = evt;

// One complication: field names are only inferred from the
// fact that we are in Object context...
// One complication: field names are only inferred from the fact that we are
// in Object context; they are just ScalarEvents (but separate and NOT just tagged
// on values)
if (_parsingContext.inObject()) {
if (_currToken != JsonToken.FIELD_NAME) {
if (!evt.is(Event.ID.Scalar)) {
Expand All @@ -383,11 +383,20 @@ public JsonToken nextToken() throws IOException
}
_reportError("Expected a field name (Scalar value in YAML), got this instead: "+evt);
}
ScalarEvent scalar = (ScalarEvent) evt;
String name = scalar.getValue();
// 20-Feb-2019, tatu: [dataformats-text#123] Looks like YAML exposes Anchor for Object at point
// where we return START_OBJECT (which makes sense), but, alas, Jackson expects that at point
// after first FIELD_NAME. So we will need to defer clearing of the anchor slightly,
// just for the very first entry; and only if no anchor for name found.
// ... not even 100% sure this is correct, or robust, but does appear to work for specific
// test case given.
final ScalarEvent scalar = (ScalarEvent) evt;
final String newAnchor = scalar.getAnchor();
if ((newAnchor != null) || (_currToken != JsonToken.START_OBJECT)) {
_currentAnchor = scalar.getAnchor();
}
final String name = scalar.getValue();
_currentFieldName = name;
_parsingContext.setCurrentName(name);
_currentAnchor = scalar.getAnchor();
return (_currToken = JsonToken.FIELD_NAME);
}
}
Expand Down Expand Up @@ -856,10 +865,8 @@ public String getTypeId() throws IOException, JsonGenerationException
return null;
}
if (tag != null) {
/* 04-Aug-2013, tatu: Looks like YAML parser's expose these in...
* somewhat exotic ways sometimes. So let's prepare to peel off
* some wrappings:
*/
// 04-Aug-2013, tatu: Looks like YAML parser's expose these in... somewhat exotic
// ways sometimes. So let's prepare to peel off some wrappings:
while (tag.startsWith("!")) {
tag = tag.substring(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Although native Object Ids work in general, Tree Model currently
* has issues with it (see [dataformat-yaml#24])
*/
public class ObjectIdTest extends ModuleTestBase
public class ObjectIdWithTreeTest extends ModuleTestBase
{
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
static class Node
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.fasterxml.jackson.dataformat.yaml.misc;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.*;

//for [dataformats-text#123], problem with YAML, Object Ids
public class ObjectId123Test extends ModuleTestBase
{
private final ObjectMapper MAPPER = newObjectMapper();

public void testObjectIdUsingNative() throws Exception
{
final String YAML_CONTENT =
"foo: &foo1\n" +
" value: bar\n" +
"boo: *foo1\n";
ScratchModel result = MAPPER.readValue(YAML_CONTENT, ScratchModel.class);
assertNotNull(result);
assertNotNull(result.foo);
assertNotNull(result. boo);
assertSame(result.foo, result.boo);
}

static class ScratchModel {
public StringHolder foo;
public StringHolder boo;
}

// @JsonIdentityInfo(generator = ObjectIdGenerators.None.class)
@JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class)
static class StringHolder {
public String value;

@Override
public String toString() {
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.yaml.failing;
package com.fasterxml.jackson.dataformat.yaml.misc;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
Expand Down

0 comments on commit cb7ea05

Please sign in to comment.