You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2014/03/07 21:55:18 UTC

Use javascriptsupport.require.with() directly with Jackson

Hi guys, I'm trying to use Jackson directly with
javascriptsupport.require.with() like so

ObjectMapper mapper = new ObjectMapper();ObjectNode node =
mapper.valueToTree(pojo);

javascriptsupport.require.with(node);


However I get the following exception

JSONObject properties may be one of Boolean, Number, String,
org.apache.tapestry5.json.JSONArray, org.apache.tapestry5.json.JSONLiteral,
org.apache.tapestry5.json.JSONObject,
org.apache.tapestry5.json.JSONObject$Null,
org.apache.tapestry5.json.JSONString. Type
org.codehaus.jackson.node.ObjectNode is not allowed. -

I can't seem to find the API on require, does anybody know how I could use
jackson directly without having to first convert my Jackson object to a
string and then pass it into JSONObject?

Thanks,

-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Use javascriptsupport.require.with() directly with Jackson

Posted by George Christman <gc...@cardaddy.com>.
Thanks Thiago.


On Mon, Mar 10, 2014 at 3:30 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 10 Mar 2014 12:27:29 -0300, George Christman <
> gchristman@cardaddy.com> wrote:
>
>  I was thinking Jackson could build a json object ready to be passed to
>> the clientside without having to first convert it to a string then pass it
>> into my JSONObject. I'm trying to avoid the last two steps.
>>
>
> In this case, I think you'll need to write a Tapestry JSONObject mapping
> for Jackson if someone else didn't do it in an open source project yet.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Use javascriptsupport.require.with() directly with Jackson

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 10 Mar 2014 12:27:29 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> I was thinking Jackson could build a json object ready to be passed to  
> the clientside without having to first convert it to a string then pass  
> it into my JSONObject. I'm trying to avoid the last two steps.

In this case, I think you'll need to write a Tapestry JSONObject mapping  
for Jackson if someone else didn't do it in an open source project yet.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Use javascriptsupport.require.with() directly with Jackson

Posted by George Christman <gc...@cardaddy.com>.
Yes serverside and Jackson will convert java objects to json and I'm trying
to pass the generated json object to clientside. I'm building a custom
implementation of modal and I'm looking to pass a JSONObject into
javascriptsupport.require.with(); This works fine if I convert the
generated json into a string then pass it into the JSONObject() like so

public JSONObject toJSON() throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        return new JSONObject(mapper.writeValueAsString(new
Warnings(warnings)));
}

javaScriptSupport.require("warnings-modal-dialog").with(storage.getWarning().toJSON());

however that is very inefficient and if I try to do it as followed I get
the below exception

 ObjectMapper mapper = new ObjectMapper();ObjectNode node =
mapper.valueToTree(pojo);

javascriptsupport.require.with(node);

JSONObject properties may be one of Boolean, Number,
String,org.apache.tapestry5.json.
JSONArray, org.apache.tapestry5.json.JSONLiteral,

I was thinking Jackson could build a json object ready to be passed to the
clientside without having to first convert it to a string then pass it into
my JSONObject. I'm trying to avoid the last two steps.


On Sat, Mar 8, 2014 at 1:22 AM, Geoff Callender <
geoff.callender.jumpstart@gmail.com> wrote:

> I'm very confused as to what you're trying to achieve. This is
> server-side, yeah? Isn't Jackson's purpose to convert between Java objects
> and JSON? Are you wanting to pass JSON to client-side? What's the name of
> the client-side JavaScript module? Does it expect parameter(s)? What type?
> (You can pass JSONObject, Boolean, Number, String, JSONArray, JSONLiteral,
> JSONObject, JSONString, as the exception message says.) How will you
> convert from Jackson's output to one of those types? Maybe you could use
> ObjectMapper#writeValue(...) as input to JSONLiteral, pass it to the
> client-side, and the module could parse it to JSON?
>
> JavaScriptSupport#require(String moduleName) returns an Initialization.
> Initialization#with(Object... arguments) expects the types noted above.
> The number of args has to match the number of args client-side.
>
> See
> http://people.apache.org/~hlship/t5api/apidocs/org/apache/tapestry5/services/javascript/JavaScriptSupport.html#require(java.lang.String)
>
> But all of this begs the question, is this heading in the right direction?
>
> HTH,
>
> Geoff
>
> On 08/03/2014, at 7:55 AM, George Christman wrote:
>
> > Hi guys, I'm trying to use Jackson directly with
> > javascriptsupport.require.with() like so
> >
> > ObjectMapper mapper = new ObjectMapper();ObjectNode node =
> > mapper.valueToTree(pojo);
> >
> > javascriptsupport.require.with(node);
> >
> >
> > However I get the following exception
> >
> > JSONObject properties may be one of Boolean, Number, String,
> > org.apache.tapestry5.json.JSONArray,
> org.apache.tapestry5.json.JSONLiteral,
> > org.apache.tapestry5.json.JSONObject,
> > org.apache.tapestry5.json.JSONObject$Null,
> > org.apache.tapestry5.json.JSONString. Type
> > org.codehaus.jackson.node.ObjectNode is not allowed. -
> >
> > I can't seem to find the API on require, does anybody know how I could
> use
> > jackson directly without having to first convert my Jackson object to a
> > string and then pass it into JSONObject?
> >
> > Thanks,
> >
> > --
> > George Christman
> > www.CarDaddy.com
> > P.O. Box 735
> > Johnstown, New York
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Use javascriptsupport.require.with() directly with Jackson

Posted by Geoff Callender <ge...@gmail.com>.
I'm very confused as to what you're trying to achieve. This is server-side, yeah? Isn't Jackson's purpose to convert between Java objects and JSON? Are you wanting to pass JSON to client-side? What's the name of the client-side JavaScript module? Does it expect parameter(s)? What type? (You can pass JSONObject, Boolean, Number, String, JSONArray, JSONLiteral, JSONObject, JSONString, as the exception message says.) How will you convert from Jackson's output to one of those types? Maybe you could use ObjectMapper#writeValue(...) as input to JSONLiteral, pass it to the client-side, and the module could parse it to JSON?

JavaScriptSupport#require(String moduleName) returns an Initialization.
Initialization#with(Object... arguments) expects the types noted above. The number of args has to match the number of args client-side.

See http://people.apache.org/~hlship/t5api/apidocs/org/apache/tapestry5/services/javascript/JavaScriptSupport.html#require(java.lang.String)

But all of this begs the question, is this heading in the right direction?

HTH,

Geoff

On 08/03/2014, at 7:55 AM, George Christman wrote:

> Hi guys, I'm trying to use Jackson directly with
> javascriptsupport.require.with() like so
> 
> ObjectMapper mapper = new ObjectMapper();ObjectNode node =
> mapper.valueToTree(pojo);
> 
> javascriptsupport.require.with(node);
> 
> 
> However I get the following exception
> 
> JSONObject properties may be one of Boolean, Number, String,
> org.apache.tapestry5.json.JSONArray, org.apache.tapestry5.json.JSONLiteral,
> org.apache.tapestry5.json.JSONObject,
> org.apache.tapestry5.json.JSONObject$Null,
> org.apache.tapestry5.json.JSONString. Type
> org.codehaus.jackson.node.ObjectNode is not allowed. -
> 
> I can't seem to find the API on require, does anybody know how I could use
> jackson directly without having to first convert my Jackson object to a
> string and then pass it into JSONObject?
> 
> Thanks,
> 
> -- 
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org