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.jumpst...@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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


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

Reply via email to