You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by ant elder <an...@apache.org> on 2010/09/02 14:38:31 UTC
Re: tutorial - using binding.rest with non-jaxrs service?
On Tue, Aug 31, 2010 at 9:01 PM, Luciano Resende <lu...@gmail.com> wrote:
> On Tue, Aug 31, 2010 at 12:10 PM, ant elder <an...@apache.org> wrote:
>> Mmm, it looks like its a problem with the json data binding not being
>> able to convert an int response value into a json string.
>>
>
> It looks like we might be missing two things in the JSON databinding :
>
> - A SimpleType transformer (e.g SimpleType2JSON)
> - Properly configuring the transformer in the PullTransformer file
> (src/main/resources/META-INF/org.apache.tuscany.databinding.PullTransformer)
> with something like
>
> org.apache.tuscany.sca.databinding.json.jackson.SimpleType2JSON;source=java:simpleType,target=JSON,weight=90000,public=false
>
> What does the "Databinding Experts" think ?
>
Raymond, I think that question was to you as you wrote the json data
binding and I'm not sure anyone else understands it any detail how it
works, so have you any comments?
...ant
Re: tutorial - using binding.rest with non-jaxrs service?
Posted by Simon Laws <si...@googlemail.com>.
Ok, it doesn't seem to affect the build so I checked the simple fix in
at revision: 992281. Obviously Raymond feel free to amend if you see
more to do.
Simon
--
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com
Re: tutorial - using binding.rest with non-jaxrs service?
Posted by Raymond Feng <en...@gmail.com>.
It looks good on the surface. I'll take a look later in more details.
Thanks,
Raymond
________________________________________________________________
Raymond Feng
rfeng@apache.org
Apache Tuscany PMC member and committer: tuscany.apache.org
Co-author of Tuscany SCA In Action book: www.tuscanyinaction.com
Personal Web Site: www.enjoyjava.com
________________________________________________________________
On Sep 2, 2010, at 6:53 AM, Simon Laws wrote:
> On Thu, Sep 2, 2010 at 1:38 PM, ant elder <an...@apache.org> wrote:
>> On Tue, Aug 31, 2010 at 9:01 PM, Luciano Resende <lu...@gmail.com> wrote:
>>> On Tue, Aug 31, 2010 at 12:10 PM, ant elder <an...@apache.org> wrote:
>>>> Mmm, it looks like its a problem with the json data binding not being
>>>> able to convert an int response value into a json string.
>>>>
>>>
>>> It looks like we might be missing two things in the JSON databinding :
>>>
>>> - A SimpleType transformer (e.g SimpleType2JSON)
>>> - Properly configuring the transformer in the PullTransformer file
>>> (src/main/resources/META-INF/org.apache.tuscany.databinding.PullTransformer)
>>> with something like
>>>
>>> org.apache.tuscany.sca.databinding.json.jackson.SimpleType2JSON;source=java:simpleType,target=JSON,weight=90000,public=false
>>>
>>> What does the "Databinding Experts" think ?
>>>
>>
>> Raymond, I think that question was to you as you wrote the json data
>> binding and I'm not sure anyone else understands it any detail how it
>> works, so have you any comments?
>>
>> ...ant
>>
>
> I took a quick look at this. The error in Florian's sample is
> occurring when the runtime tries to convert the primitve type response
> back to JSON representation. It has code to pick up strings but not
> primitives. In both cases I think it should just return the value
> as-is and not try to do any conversion on it. In the JSONP servlet
> we'll wrap the returned value in the callback name and, in the error
> case, I believe we expect to see something like....
>
> shareAgeCallback(54);
>
> I.e the value returned by public int shareAge(int age); is just
> presented as an int.
>
> This needs an extra test to see if the response target type is a
> primitive alongside the test to see it it's a String.
>
> I've made the change locally and this allows the sample to run however
> I'm having trouble with lots of failures in the full build at the
> moment (anyone else seeing failures?) so I'll hold back from checking
> it in. If you want to try it this is the change:
>
> Index: src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java
> ===================================================================
> --- src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java (revision
> 991885)
> +++ src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java (working
> copy)
> @@ -54,7 +54,7 @@
> }
> try {
> String value = mapper.writeValueAsString(source);
> - if (targetType == String.class || targetType == Object.class) {
> + if (targetType == String.class || targetType ==
> Object.class || targetType.isPrimitive()) {
> return value;
> } else if (JsonNode.class.isAssignableFrom(targetType)) {
> return JacksonHelper.createJsonParser(value).readValueAsTree();
>
>
> Simon
>
> --
> Apache Tuscany committer: tuscany.apache.org
> Co-author of a book about Tuscany and SCA: tuscanyinaction.com
Re: tutorial - using binding.rest with non-jaxrs service?
Posted by Simon Laws <si...@googlemail.com>.
On Thu, Sep 2, 2010 at 1:38 PM, ant elder <an...@apache.org> wrote:
> On Tue, Aug 31, 2010 at 9:01 PM, Luciano Resende <lu...@gmail.com> wrote:
>> On Tue, Aug 31, 2010 at 12:10 PM, ant elder <an...@apache.org> wrote:
>>> Mmm, it looks like its a problem with the json data binding not being
>>> able to convert an int response value into a json string.
>>>
>>
>> It looks like we might be missing two things in the JSON databinding :
>>
>> - A SimpleType transformer (e.g SimpleType2JSON)
>> - Properly configuring the transformer in the PullTransformer file
>> (src/main/resources/META-INF/org.apache.tuscany.databinding.PullTransformer)
>> with something like
>>
>> org.apache.tuscany.sca.databinding.json.jackson.SimpleType2JSON;source=java:simpleType,target=JSON,weight=90000,public=false
>>
>> What does the "Databinding Experts" think ?
>>
>
> Raymond, I think that question was to you as you wrote the json data
> binding and I'm not sure anyone else understands it any detail how it
> works, so have you any comments?
>
> ...ant
>
I took a quick look at this. The error in Florian's sample is
occurring when the runtime tries to convert the primitve type response
back to JSON representation. It has code to pick up strings but not
primitives. In both cases I think it should just return the value
as-is and not try to do any conversion on it. In the JSONP servlet
we'll wrap the returned value in the callback name and, in the error
case, I believe we expect to see something like....
shareAgeCallback(54);
I.e the value returned by public int shareAge(int age); is just
presented as an int.
This needs an extra test to see if the response target type is a
primitive alongside the test to see it it's a String.
I've made the change locally and this allows the sample to run however
I'm having trouble with lots of failures in the full build at the
moment (anyone else seeing failures?) so I'll hold back from checking
it in. If you want to try it this is the change:
Index: src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java
===================================================================
--- src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java (revision
991885)
+++ src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java (working
copy)
@@ -54,7 +54,7 @@
}
try {
String value = mapper.writeValueAsString(source);
- if (targetType == String.class || targetType == Object.class) {
+ if (targetType == String.class || targetType ==
Object.class || targetType.isPrimitive()) {
return value;
} else if (JsonNode.class.isAssignableFrom(targetType)) {
return JacksonHelper.createJsonParser(value).readValueAsTree();
Simon
--
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com