1

I have a model such as bellow.

public class ColumnDtoWrapper extends JavaScriptObject{

protected ColumnDtoWrapper() {}

public final native JsArray<ColumnDto> getfields() /*-{
    return this.fields;
}-*/;

public final native void gettable() /*-{
return this.table;
}-*/;

public final native JavaScriptObject getHasMany() /*-{
    return this.hasmany;
}-*/;
}

I Make server call like

RequestBuilder build = new RequestBuilder(RequestBuilder.POST, URL);
    try {
        Request request = build.sendRequest(null, new RequestCallback(){
            @Override
            public void onResponseReceived(Request request, Response response) {
                if(200== response.getStatusCode()){

                    }
                }

            @Override
            public void onError(Request request, Throwable exception) {
                Window.alert("error : " + exception.getLocalizedMessage());
            }

        });
    } catch (Exception e) {
        Window.alert("try err");
    }

When i got success responce in JSON string. I want to convert that string as ColumnsDtoWrapper.

somthing like ColumnDtoWrapper col = new ColumnDtoWrapper(responce.getText());

but it not works is there any good way to convert string to JavaScriptObject?

1 Answer 1

2

Use JsonUtils.safeEval:

ColumnDtoWrapper col = JsonUtils.safeEval(response.getText());
Sign up to request clarification or add additional context in comments.

1 Comment

i uses following way.public static final native <T extends ColumnDtoWrapper> T getResponse(String responseString) /*-{ return eval('(' + responseString + ')'); }-*/;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.