How to Resolve an Uncaught Exception Thrown by REST Service: Unrecognized "input" field

Hi I am writing a rest service where the user enters a value in a dialog and through Ajax it updates the table of active objects. But I keep getting Unirradiated Exception thrown by REST service: unrecognized "input" field.

@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Path("/message")
public class LeangearsRestResource {


    ActorConfService ActorConfService;

    private final ApplicationProperties applicationProperties;
    public LeangearsRestResource(ApplicationProperties applicationProperties, ActorConfService actorConfService){
        this.applicationProperties = applicationProperties;
        this.actorConfService = actorConfService;
    }
    static final javax.ws.rs.core.CacheControl NO_CACHE = new javax.ws.rs.core.CacheControl();

    @POST
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response addMessage(ActorBeans actorBeans)
    {

        if(actorConfService.add(actorBeans.getActor(),actorBeans.getRole()))
        {
            return Response.ok(new Result(true)).cacheControl(NO_CACHE).build();
        }
        return Response.ok(new Result(false)).cacheControl(NO_CACHE).build();
    }

      

ActorBean.java

@XmlAccessorType(XmlAccessType.FIELD)
public class ActorBeans {


/*
    @XmlElement(name = "projectName")
    String productName;*/
    @XmlElement(name = "actor")
    String actor;
    @XmlElement(name = "role")
    String role;

    public ActorBeans() {
    }

    public ActorBeans(String productName, String actor, String role){
        /*this.productName = productName;*/
        this.actor = actor;
        this.role =role;
    }

    /*public void setProductName(String productName) {

        this.productName = productName;
    }

    public String getProductName(){

        return productName;
    }*/


    public String getActor() {
        return actor;
    }

    public void setActor(String actor) {
        this.actor = actor;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }
}

      

actor.js

function actor_createPostAjaxOptions (data, data1) {
    return {
        "cache": false,
        "contentType": 'application/json',
        "dataType": 'json',
        "data": JSON.stringify(data, data1),
        "processData": false,
        "type": 'POST'
    };
}

function actor_createDeleteAjaxOptions (data) {
    return {
        "cache": false,
        "contentType": 'application/json',
        "dataType": 'json',
        "data": JSON.stringify(data),
        "processData": false,
        "type": 'DELETE'
    };
}




AJS.$( function(){
    // Standard sizes are 400, 600, 800 and 960 pixels wide
    var actor_dialog = new AJS.Dialog({
        width: 400,
        height: 300,
        id: "example-dialog",
        closeOnOutsideClick: true
    });

    // PAGE 0 (first page)
    // adds header for first page
    actor_dialog.addHeader("Actor");

    // add panel 1
    actor_dialog.addPanel("Panel 1", "<input id='dialoginput' type='text' value=''>Actor1</input>" + "<br>" + "<input id='dialoginput1' type='text' value=''>Actor2</input>" , "panel-body");


    actor_dialog.addLink("Cancel", function (actor_dialog) {
        actor_dialog.hide();
    }, "#");



    actor_dialog.addSubmit(
        "Submit",
        function(actor_dialog) {
            actor_dialog.hide();
            AJS.log(AJS.$("#dialoginput").val());
            data = {input:AJS.$("#dialoginput").val()};

            data1 = {input:AJS.$("#dialoginput1").val()};
            jQuery.ajax(
                AJS.params.baseURL+"/rest/leangearsrestresource/1.0/message",
                actor_createPostAjaxOptions(data, data1)
            )
            AJS.$("#test").html(AJS.$("#dialoginput").val())
            AJS.$("#test1").html(AJS.$("#dialoginput1").val())
        }
    );

    // Add events to dialog trigger elements
    AJS.$("#dialog-button").click(function() {
        // PREPARE FOR DISPLAY
        // start first page, first panel
        //debugger;

        //call ajax to get existing value
        jQuery.ajax(
            AJS.params.baseURL+"/rest/leangearsrestresource/1.0/message",
            {
                "cache": false,
                "processData": false,
                "type": 'GET',
                "contentType": 'application/json',
                "dataType": 'json'
            }).done(function(result) {

                AJS.log(result);

                AJS.$("#dialoginput").val(result.value);
                actor_dialog.gotoPage(0);
                actor_dialog.gotoPanel(0);
                actor_dialog.show();



            }).fail(function() {
                AJS.log("failed get GET");

            });


    });

})

      

+3


source to share


1 answer


"Unrecognized field input" message (class com.leanpitch.leangears.jira.webwork.beans.ActorBeans) not marked as "clueless"

See what you have here.

data = {input:AJS.$("#dialoginput").val()};
data1 = {input:AJS.$("#dialoginput1").val()};

actor_createPostAjaxOptions(data, data1)
[..] 
"data": JSON.stringify(data, data1),

      

The message is pretty clear. It says you have a JSON with an "input" field that the server doesn't know how to handle. Look at this

data = {input:AJS.$("#dialoginput").val()};

      

Regardless AJS.$("#dialoginput").val()

, that is, the value of the field "input"

. So if value "value"

then the JSON sent will be

{ "input" : "value" }

      

As for data1

, I don't think it was sent. AFAIK, JSON.stringify

should only accept one Javascript object as a data argument, that is, the object it will compress.



Now view your Java Object

public class ActorBeans {

    @XmlElement(name = "actor")
    String actor;
    @XmlElement(name = "role")
    String role;

      

This means that the expected JSON is in the format

{ "actor" : "value", "role" : "value" }

      

JSON is pretty close to the same syntax as JSON, so it's pretty much what a Javacript object should look like. This way you can have a Javascript object like

var data = {
    actor: AJS.$("#dialoginput").val(),
    role: AJS.$("#dialoginput1").val()
};

      

Then you can submit this message data

for sending.

+1


source







All Articles