简体   繁体   中英

unable to recognize field - not marked as ignorable error - JSON - Java object

I am getting the below error when I try to post the input field values to my controller/method and convert the JSON to java object. I couldn't figure out where the error is.

Can some one please help me solve this?

Error:

Unrecognized field "userId" (Class models.SignupCred), not marked as ignorable at [Source: N/A; line: -1, column: -1] (through reference chain: models.SignupCred["userId"])

Model:

import org.codehaus.jackson.annotate.JsonIgnoreProperties;    
import com.google.code.morphia.annotations.Id;

@JsonIgnoreProperties
public class SignupCred {
    @Id
    String userId;
    String firstName;
    String lastName;
    String langCode;
    String email;
    String password;
    String residentCountryCode;
    String contactPrefEmail;
}

Javascript:

$(document).ready(function () {
    $("#signup").click(function() {  
        var user = new Object();
        user.userId = $('#userId').val();
        user.firstName = $('#firstName').val();
        user.lastName = $('#lastName').val();
        user.langCode = $('#langCode').val();
        user.Email = $('#email').val();
        user.password = $('#password').val();
        user.residentCountryCode = $('#residentCountryCode').val();
        user.contactPrefEmail = $('#contactPrefEmail').val();

        $.ajax({
            url: "/submitsignup",
            type: "POST",
            contentType: "application/json",
            data: JSON.stringify(user),     
            success: function(data, textStatus, xhr) {
                var resp = JSON.parse(xhr.responseText);
                window.location.replace(resp.message);
            }

        });
      });  

});

Controller:

public Result submitsignup()
    {
        JsonNode node = request().body().asJson();
        SignupCred signupdata=null;
        try {
            signupdata = objectMapper.readValue(node, SignupCred.class);
            if (signupdata == null) 
                return status(BAD_REQUEST, GenericUtils.createErrorResponseAsJson(BAD_REQUEST, Messages.get("error sign up AC.java", "")));
            String userId = signupservice.createUser(signupdata);
            if(userId!=null)
            {
                String userType="myacct1";
                if (userType!=null) {
                    session(Constants.USERTYPE,userType);
                    session(Constants.LOGIN_KEY, "myacct1");
                }}} 

        catch(Exception e)
        {
            Logger.error(e.getMessage());
        }
        return ok(index.render("Login"));
    }

signup.scala.html:

<div class="login-input-container">                         
    <div class="error-message-container login" id="errorMessageContainer" style="display:none">     
      <p id="errorMessage" class="error-text"></p>
    </div>
    <input id="userId" name="userId" type="text" placeholder="userId" autocomplete="off" class="inputtag"/> 
    <input id="firstName" name="firstName" type="text" placeholder="firstName" autocomplete="off" class="inputtag"/>        
    <input id="lastName" name="lastName" type="text" placeholder="lastName" class="inputtag" />
    <input id="langCode" name="langCode" type="text" placeholder="en" class="inputtag" />
    <input id="email" name="email" type="text" placeholder="email" class="inputtag" />
    <input id="password" name="password" type="text" placeholder="Password" class="inputtag" />
    <input id="residentCountryCode" name="residentCountryCode" type="text" placeholder="ISO country code" class="inputtag" />
    <input id="contactPrefEmail" name="contactPrefEmail" type="text" placeholder="Y" class="inputtag" />
    <input type="button" class="btn" value="Already a User?" id="signin" onclick="/loginpage"/>
    <input type="button" class="btn" value="Sign Up" id="signup"/>  
</div>

Problem is with user.Email . It should be user.email

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM