Dear all,
I'm using Xtext 2.3 and would like to generate Json files out of a UML model (using ATL as M2M languange). The case where an object is empty (which is allowed by the Json Xtext grammar) renders exception message "Could not serialize EObject via backtracking". Seems to be an old issue, but I could still not figure out how to fix it, so any (carefully explained) hints are most welcome!
Thanks a lot!
/Andreas
Complete Xtext Grammar
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate json "<url not allowed>"
Object:
'{'
(members+=Member)?
(',' members+=Member)*
'}'
;
Member:
key=STRING ':' value=Value;
Value:
Object |
StringValue |
Array |
Boolean |
Null |
Number
;
Array:
'[' (values+=Value)? (',' values+=Value)* ']';
StringValue:
value=(STRING);
Boolean:
'true' | 'false';
Null:
'null';
terminal Number:
'-'? INT? '.' INT (('E'|'e') '-'? INT)?;
Complete XML file to be serialized
<?xml version="1.0" encoding="ISO-8859-1"?>
<json:Object xmi:version="2.0" xmlns:xmi="url to XMI" xmlns:xsi="url to XMLSchema-instance" xmlns:json="url not allowed">
<members key="emptyMember">
<value xsi:type="json:Object"/>
</members>
</json:Object>
Excpected serialized .json output
Instead the following exception is thrown
java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null (members+=Member members+=Member* | members+=Member*) null
Values:
Semantic Object: Object.members[1]->Member.value->Object
Context: Value
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(Unknown Source)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(Unknown Source)
at a.b.c.d.serializer.JsonSemanticSequencer.sequence_Object(Unknown Source)
at a.b.c.d.serializer.JsonSemanticSequencer.createSequence(Unknown Source)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(Unknown Source)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(Unknown Source)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(Unknown Source)
at a.b.c.d.serializer.JsonSemanticSequencer.sequence_Member(Unknown Source)
at a.b.c.d.serializer.JsonSemanticSequencer.createSequence(Unknown Source)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(Unknown Source)
...