Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Json empty object serialization problem (Could not serialize EObject via backtracking)
Json empty object serialization problem [message #896680] Thu, 19 July 2012 11:18 Go to next message
Andreas Jakobik is currently offline Andreas JakobikFriend
Messages: 12
Registered: November 2011
Junior Member
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

{
   "emptyMember" : {} 
}


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)
        ...

Re: Json empty object serialization problem [message #897771 is a reply to message #896680] Wed, 25 July 2012 08:45 Go to previous message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi Andreas,
You need an action to ensure "some" object is created. So for example set the Object grammar to the following:

Object:
{Object}'{'
(members+=Member)?
(',' members+=Member)*
'}'
;

The {Object} action seems to ensure that your grammar can create a {}. This works fine with ATL and the generated editor.

The grammar seems a little odd to me so maybe someone else can explain why it must be like this?

Regards,
Ronan
Previous Topic:weird error with Guice
Next Topic:Xtext and scopes
Goto Forum:
  


Current Time: Wed Jul 08 05:51:39 GMT 2020

Powered by FUDForum. Page generated in 0.01617 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top