1

当我尝试将输入字段值发布到我的控制器/方法并将JSON转换为java对象时,出现以下错误。我无法弄清楚错误在哪里。

有人可以帮我解决这个问题吗?

错误:

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

模型:

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);
            }

        });
      });  

});

控制器:

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"));
    }

注册.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>
4

1 回答 1

0

问题出在user.Email 上。它应该是user.email

于 2015-09-14T10:19:42.603 回答