无法识别字段-未标记为可忽略错误-JSON-Java对象
unable to recognize field - not marked as ignorable error - JSON - Java object
当我试图将输入字段值发布到我的控制器/方法并将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>
问题出在用户身上。电子邮件。应该是user.Email
相关文章:
- 将纯文本URL转换为可单击链接
- 将日期时间从json转换为可读格式
- 在HTML页面上将URL解析为可读的json格式
- 将桌面上的悬停导航栏转换为触摸屏上的可点击导航栏
- 在es6中,将带有回调的事件侦听器设置为可迭代的
- 将代码转换为可重用对象
- 用javascript将epoch时间转换为可读格式
- 如何将页面上的所有电话号码更改为可点击链接,不包括特定类别的元素
- 将js对象更改为使用嵌套的可观察数组敲除js视图模型
- 如果在构造函数内部为else,则Javascript是可选的
- KnockoutJS可观测值为't通过选择设置
- FullCalendar可在设置为本地时区时调整时区,但不适用于欧洲/雅典
- 无法识别字段-未标记为可忽略错误-JSON-Java对象
- 拖放,使可拖动为假
- 如何限制jquery的可选选项为1 tr,并将选择的项目传递到另一个页面
- Bootstrap可忽略警报不起作用
- Adobe LiveCycle设计器-表单脚本-将字段从可选更改为必需
- HTML选项-当可观察对象为null时显示默认值
- 为什么在我点击关闭按钮后不显示可忽略的警报?
- 您可以为“保存为”设置文件名吗?在带有data url的图像上