Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [texo] how to set references in json
[texo] how to set references in json [message #899957] Fri, 03 August 2012 04:28 Go to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 729
Registered: July 2009
Senior Member
I have the following model:

Class A
  - id : long

Class B
  - a : A



How do I set a reference to A in B when preparing the json string for HTTP PUT?

I tried to put the long id, but texo complains:

java.lang.ClassCastException: java.lang.Integer cannot be cast to org.json.JSONObject
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertSingleEReference(BaseJSONModelConverter.java:247)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:214)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
	at org.eclipse.emf.texo.server.service.json.JSONServiceContext.getRequestData(JSONServiceContext.java:91)
	at org.eclipse.emf.texo.server.service.UpdateInsertModelOperation.internalExecute(UpdateInsertModelOperation.java:42)
	at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:48)
	at org.eclipse.emf.texo.server.web.WebServiceHandler.doPost(WebServiceHandler.java:107)
	at org.eclipse.emf.texo.server.web.WebServiceHandler.doPut(WebServiceHandler.java:121)
	at org.eclipse.emf.texo.server.web.WebServiceServlet.doPut(WebServiceServlet.java:73)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.eclipse.emf.texo.server.store.CurrentEntityManagerRequestFilter.doFilter(CurrentEntityManagerRequestFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)


My json string looks like this:

{
  a: 1,
  "_eclass": "mypackage|B"
}


Note: an instance of A is available and 1 is the id of that instance.
Re: [texo] how to set references in json [message #900114 is a reply to message #899957] Sat, 04 August 2012 03:18 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5326
Registered: July 2009
Senior Member
Hi Erdal,
A reference should also be a json object, so something like this:
{
a: {id: 1},
"_eclass": "mypackage|B"
}

Maybe you have to add the _eclass attribute to the 'a' json object, but can you try first without to see if it works.

gr. Martin


On 08/03/2012 10:28 AM, Erdal Karaca wrote:
> I have the following model:
>
> Class A
> - id : long
>
> Class B
> - a : A
>
>
>
> How do I set a reference to A in B when preparing the json string for HTTP PUT?
>
> I tried to put the long id, but texo complains:
>
>
> java.lang.ClassCastException: java.lang.Integer cannot be cast to org.json.JSONObject
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertSingleEReference(BaseJSONModelConverter.java:247)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:214)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
> at org.eclipse.emf.texo.server.service.json.JSONServiceContext.getRequestData(JSONServiceContext.java:91)
> at org.eclipse.emf.texo.server.service.UpdateInsertModelOperation.internalExecute(UpdateInsertModelOperation.java:42)
> at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:48)
> at org.eclipse.emf.texo.server.web.WebServiceHandler.doPost(WebServiceHandler.java:107)
> at org.eclipse.emf.texo.server.web.WebServiceHandler.doPut(WebServiceHandler.java:121)
> at org.eclipse.emf.texo.server.web.WebServiceServlet.doPut(WebServiceServlet.java:73)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
> org.eclipse.emf.texo.server.store.CurrentEntityManagerRequestFilter.doFilter(CurrentEntityManagerRequestFilter.java:65)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
> at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
>
> My json string looks like this:
>
>
> {
> a: 1,
> "_eclass": "mypackage|B"
> }
>
>
> Note: an instance of A is available and 1 is the id of that instance.
>


--

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
Re: [texo] how to set references in json [message #900132 is a reply to message #900114] Sat, 04 August 2012 08:16 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 729
Registered: July 2009
Senior Member
Martin,
The reference update works with the _eclass property set.

E.g.

{
   a: {"id": 1, "_eclass": "mypackage|A"},
   "_eclass": "mypackage|B"
}


Martin taal wrote on Sat, 04 August 2012 03:18
Hi Erdal,
A reference should also be a json object, so something like this:
{
a: {id: 1},
"_eclass": "mypackage|B"
}

Maybe you have to add the _eclass attribute to the 'a' json object, but can you try first without to see if it works.

gr. Martin


Re: [texo] how to set references in json [message #900443 is a reply to message #900132] Tue, 07 August 2012 02:37 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5326
Registered: July 2009
Senior Member
Hi Erdal,
I published a new build which should support this without the _eclass property also, can you retry?

gr. Martin

On 08/04/2012 02:16 PM, Erdal Karaca wrote:
> Martin,
> The reference update works with the _eclass property set.
>
> E.g.
>
>
> {
> a: {"id": 1, "_eclass": "mypackage|A"},
> "_eclass": "mypackage|B"
> }
>
>
> Martin taal wrote on Sat, 04 August 2012 03:18
>> Hi Erdal,
>> A reference should also be a json object, so something like this:
>> {
>> a: {id: 1},
>> "_eclass": "mypackage|B"
>> }
>>
>> Maybe you have to add the _eclass attribute to the 'a' json object, but can you try first without to see if it works.
>>
>> gr. Martin
>
>


--

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
Re: [texo] how to set references in json [message #902671 is a reply to message #900443] Sun, 19 August 2012 08:55 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 729
Registered: July 2009
Senior Member
Seems to work for GET, but not for POST.
Re: [texo] how to set references in json [message #902674 is a reply to message #902671] Sun, 19 August 2012 08:56 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 729
Registered: July 2009
Senior Member
Though, POST is for inserting?
Re: [texo] how to set references in json [message #902680 is a reply to message #902674] Sun, 19 August 2012 09:11 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5326
Registered: July 2009
Senior Member
POST and PUT do the same, POST can be used for retrieving also depending on the request content.

But I kind of lost what the actual question was..., can you repeat it?

gr. Martin

On 08/19/2012 02:56 PM, Erdal Karaca wrote:
> Though, POST is for inserting?


--

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:[Texo] Complete tutorial (from scratch)
Next Topic:orm:delimited-identifiers
Goto Forum:
  


Current Time: Tue Jul 29 08:58:23 EDT 2014

Powered by FUDForum. Page generated in 0.03641 seconds