Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] Problems handling JSON response
[Texo] Problems handling JSON response [message #1001872] Thu, 17 January 2013 08:43 Go to next message
Bastian Wagenfeld is currently offline Bastian Wagenfeld
Messages: 161
Registered: January 2013
Senior Member
Hi!

I am interessted in using Texo in a project. So I installed it and created a little servlet. The servlet itself works, but I have problems to handle the JSON string that is returned by the server.
The string looks like that (shortened version):

{"endRow":"25","_eclass":"response|ResponseType","totalRows":"26","status":"success","startRow":"0","data":[{"_eclass":"users|User","db_version":1,"db_Id":1,"_id":"1","name":"Testuser neu","role":{"_eclass":"users|Role","db_Id":2,"_id":"2","_proxy":true,"_uri":"ht.tp://localhost:8080/texo/jsonws/users|Role/2#","_title":"Admin"},
and so on....

So i create a JSONObject with that string. No I am not sure about the following steps.
I tried the following two conversions:

1.

JSONObject obj = new JSONObject(json);
JSONModelConverter mConv = ComponentProvider.getInstance().newInstance(
				JSONModelConverter.class);
ResponseType type = (ResponseType) mConv.convert(obj);

This led to the following error message:
Exception in thread "main" java.lang.IllegalArgumentException: Fragment format not supported for fragment: 
	at org.eclipse.emf.texo.utils.ModelUtils.getTypeAndIdFromUri(ModelUtils.java:574)
	at org.eclipse.emf.texo.resolver.DefaultObjectResolver.fromUri(DefaultObjectResolver.java:235)
	at org.eclipse.emf.texo.json.JSONModelConverter.fromUri(JSONModelConverter.java:60)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.resolveObject(BaseJSONModelConverter.java:120)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:107)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:371)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:215)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
	at de.test.texo.test.TexoTest.getUser(TexoTest.java:132)
	at de.test.texo.test.TexoTest.main(TexoTest.java:104)


2.

Second approach using the JSONEMFConverter:
JSONObject obj = new JSONObject(json);
JSONEMFConverter conv = ComponentProvider.getInstance().newInstance(
				JSONEMFConverter.class);
DynamicEObjectImpl eObj = (DynamicEObjectImpl) conv.convert(obj);


Well, that is ok, but do I have any possibility to use the objects as objects of their own type? Maybe convert them from DynamicEObjectImpl?

I would be really happy about some help or hints that could help me with that.
Thanks a lot!

Bastian
Re: [Texo] Problems handling JSON response [message #1001898 is a reply to message #1001872] Thu, 17 January 2013 09:22 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5325
Registered: July 2009
Senior Member
Seems to be a duplicate of: [Texo] Problems handling ResponseType
answered it there.

gr. Martin

On 01/17/2013 02:45 PM, Bastian Wagenfeld wrote:
> Hi!
>
> I am interessted in using Texo in a project. So I installed it and created a little servlet. The servlet itself works,
> but I have problems to handle the JSON string that is returned by the server. The string looks like that (shortened
> version):
>
> {"endRow":"25","_eclass":"response|ResponseType","totalRows":"26","status":"success","startRow":"0","data":[{"_eclass":"users|User","db_version":1,"db_Id":1,"_id":"1","name":"Testuser
> neu","role":{"_eclass":"users|Role","db_Id":2,"_id":"2","_proxy":true,"_uri":"ht.tp://localhost:8080/texo/jsonws/users|Role/2#","_title":"Admin"},
> and so on....
>
> So i create a JSONObject with that string. No I am not sure about the following steps.
> I tried the following two conversions:
>
> 1.
>
>
> JSONObject obj = new JSONObject(json);
> JSONModelConverter mConv = ComponentProvider.getInstance().newInstance(
> JSONModelConverter.class);
> ResponseType type = (ResponseType) mConv.convert(obj);
>
> This led to the following error message:
> Exception in thread "main" java.lang.IllegalArgumentException: Fragment format not supported for fragment: at
> org.eclipse.emf.texo.utils.ModelUtils.getTypeAndIdFromUri(ModelUtils.java:574)
> at org.eclipse.emf.texo.resolver.DefaultObjectResolver.fromUri(DefaultObjectResolver.java:235)
> at org.eclipse.emf.texo.json.JSONModelConverter.fromUri(JSONModelConverter.java:60)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.resolveObject(BaseJSONModelConverter.java:120)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:107)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:371)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:215)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
> at de.test.texo.test.TexoTest.getUser(TexoTest.java:132)
> at de.test.texo.test.TexoTest.main(TexoTest.java:104)
>
> 2.
>
> Second approach using the JSONEMFConverter:
>
> JSONObject obj = new JSONObject(json);
> JSONEMFConverter conv = ComponentProvider.getInstance().newInstance(
> JSONEMFConverter.class);
> DynamicEObjectImpl eObj = (DynamicEObjectImpl) conv.convert(obj);
>
>
> Well, that is ok, but do I have any possibility to use the objects as objects of their own type? Maybe convert them from
> DynamicEObjectImpl?
>
> I would be really happy about some help or hints that could help me with that.
> Thanks a lot!
>
> Bastian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:How to change the default fill color of EClasses in the Ecore Tools Diagram Editor?
Next Topic:[Texo] Problems handling ResponseType
Goto Forum:
  


Current Time: Tue Jul 22 17:43:47 EDT 2014

Powered by FUDForum. Page generated in 0.02833 seconds