Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RdfJSONParser: Disable Date Parsing in Newtonsoft.JSON parser #130

Closed
kal opened this issue Nov 1, 2017 · 1 comment
Closed

RdfJSONParser: Disable Date Parsing in Newtonsoft.JSON parser #130

kal opened this issue Nov 1, 2017 · 1 comment
Assignees
Milestone

Comments

@kal
Copy link
Contributor

kal commented Nov 1, 2017

The RdfJsonParser class does not properly handle the case of a literal string that is formatted as an ISO 8601 date/time string. This code:

using VDS.RDF;
 using VDS.RDF.Parsing;
 ...
 var jsonstr = @"
 {
  ""http://example.com"": {
    ""http://purl.org/dc/terms/issued"": [{
        ""datatype"": ""http://www.w3.org/2001/XMLSchema#date"",
        ""type"": ""literal"",
        ""value"": ""2017-10-24T15:01:53+02:00""
      }]
    }
  }";

  IGraph g = new Graph();
  g.LoadFromString(str1, new RdfJsonParser());

Leads to the following exception:

Exception has occurred: CLR/VDS.RDF.Parsing.RdfParseException
Exception thrown: 'VDS.RDF.Parsing.RdfParseException' in dotNetRDF.dll: '[Line 4 Column 40 to Line 7 Column 44] Unexpected Token 'Date' encountered, expected a Property Value describing one of the properties of an Object Node'
   at VDS.RDF.Parsing.RdfJsonParser.Error(JsonParserContext context, String message, PositionInfo startPos)
   at VDS.RDF.Parsing.RdfJsonParser.ParseObject(JsonParserContext context, INode subj, INode pred)
   at VDS.RDF.Parsing.RdfJsonParser.ParseObjectList(JsonParserContext context, INode subj, INode pred)
   at VDS.RDF.Parsing.RdfJsonParser.ParsePredicateObjectList(JsonParserContext context, INode subj)
   at VDS.RDF.Parsing.RdfJsonParser.ParseTriples(JsonParserContext context)
   at VDS.RDF.Parsing.RdfJsonParser.ParseGraphObject(JsonParserContext context)
   at VDS.RDF.Parsing.RdfJsonParser.Parse(IRdfHandler handler, TextReader input)
   at VDS.RDF.Parsing.RdfJsonParser.Load(IRdfHandler handler, TextReader input)
   at VDS.RDF.Parsing.StringParser.Parse(IGraph g, String data, IRdfReader reader)

This appears to be because the underlying Newtonsoft.JSON parser has converted the ISO 8601 date string in the value property into a C# Date object, and our RdfJsonParser only expects string values.

This behaviour of the Newstonsoft parser can be disabled via the DateParseHandling property on the parser (by setting the property value to DateParseHandling.None).

Originally reported via this SO question

@kal kal added this to the 2.0 milestone Nov 1, 2017
@kal kal self-assigned this Nov 1, 2017
@pkanavos
Copy link

pkanavos commented Nov 1, 2017

Perhaps the easiest way to do this would be to set

DateParseHandling= DateParseHandling.None;

in CommentIgnoringJsonTextReader's constructors

kal pushed a commit that referenced this issue Nov 1, 2017
@kal kal closed this as completed in #131 Nov 1, 2017
kal added a commit that referenced this issue Nov 1, 2017
This PR disables the default date/time string parsing in Newtonsoft JsonTextReader. This is done in the constructor for CommentIgnoringJsonTextReader (which is shared by both the RDF/JSON parser and the SPARQL JSON parser.

Closes #130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants