On Wed, Mar 14, 2018 at 8:39 AM, Rob Oxspring <roxspr...@imapmail.org> wrote:
> Not sure whether reviving a really old thread is the right thing to do or
> not but it seems very relevant...
>
> It's very common for applications to "parse" some yaml or json by first
> using Jackson Databind to create deserialize an object model and then
> perform business level validation against that model. When doing reporting
> validation problems against that model (long after JsonParser has been
> discarded) it's invaluable to indicate a location or selection range
> associated with each problem. Forcing such users to hand code their own
> deserializer seems error prone and unnecessary duplication of effort,
> although I recognize that many use cases don't need the location info.
>
> So I wonder if it would be reasonable to add start & end JsonLocation
> properties to JsonNode, set them null by default and only populate them if
> some new DeserializationFeature.RECORD_LOCATIONS is enabled? Ideally this
> would be paired with some @JsonLocationsSetter annotation allowing POJOs to
> have location information injected into them too.
>
> Is that something that might be acceptable for v3?

I would suggest building a parallel TreeNode implementations for that, probably.
With v3 we can improve TreeNode interfaces, to allow for alternative
tree model implementations.

The challenge in adding more things into the default implementation is
that there are many kinds of things that
could make sense to add, but Java does not necessarily have mechanisms
that would allow easy addition of
mix-in style features.

JsonNode itself will not bend into keeping track of location
information for all nodes since a few node types are
light-wight style (f.ex. there are exactly 2 instances of
`BooleanNode`, ever) and immutable.
In theory it would be possible to only keep track of Location (start,
I would suggest) for properties of ObjectNode,
of course. And for that, simple sub-classing might be an option.
Plugging in of alternate implementation could
be done either via `JsonNodeFactory` or, perhaps, deserializer.

-+ Tatu +-



>
> Thanks,
>
> Rob
>
> On Monday, 14 November 2016 06:32:39 UTC, Tatu Saloranta wrote:
>>
>> No, for two reasons:
>>
>> 1. JsonNode is singly linked, only parent -> child linkage (not a
>> problem for root node itself, but in general)
>> 2. JsonNode does not have JsonLocation, since this is not needed in
>> general
>>
>> to get location information, you need to use JsonParser directly, or
>> sub-class JsonNode implementation and JsonNodeFactory. Latter might be
>> doable as you can add property to hold location information But you'd
>> need to build the tree yourself from JsonParser: this is not very
>> complicated (JsonNodeDeserializer shows how to do it, although it's
>> more complicated than what you'd need).
>>
>> -+ Tatu +-
>>
>>
>>
>> On Sat, Nov 12, 2016 at 9:13 AM,
>> <list+com.fasterxml.jackson-u...@io7m.com> wrote:
>> > Hello.
>> >
>> > Let's assume I've received an ObjectNode representing the root of a
>> > parsed JSON document. I want to extract data from that ObjectNode and
>> > therefore I'm going to be manually traversing the tree and unmarshaling
>> > fields manually. The JSON document doesn't have a schema, so I'm
>> > essentially stuck doing ad-hoc validation when I try to unmarshal
>> > fields. In order to avoid driving my users mad, I want to give good
>> > error messages such as:
>> >
>> >   error: Expected an integer value but got a string
>> >     Position: file.json:23:0
>> >     Key:      example_key
>> >
>> > Can I actually do this if I only have access to the ObjectNode? I don't
>> > see any obvious way to recover line and column numbers via the API.
>> >
>> > M
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "jackson-user" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an email to jackson-user...@googlegroups.com.
>> > To post to this group, send email to jackso...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to