使用嵌套列表将Json序列化为java pojo<;pojo>;财产

使用嵌套列表将Json序列化为java pojo<;pojo>;财产,java,jquery,json,spring-mvc,Java,Jquery,Json,Spring Mvc,下面是我的代码,试图通过jqueryajax调用向springmvc控制器发布一个Json序列化对象(javapojo具有其他pojo的列表) 从服务器获取错误的请求错误 当从Json对象中删除modalForm数据时,服务器端将正确接收MainPojo数据 Html代码 Fisrt form ------------- <form id="mainForm"> ..... </form> Form in th

下面是我的代码,试图通过jqueryajax调用向springmvc控制器发布一个Json序列化对象(javapojo具有其他pojo的列表)

从服务器获取错误的请求错误

当从Json对象中删除modalForm数据时,服务器端将正确接收MainPojo数据

Html代码

   Fisrt form
   ------------- 
    <form id="mainForm">
           .....
    </form>

    Form in the modal
    -----------------
    <form  id="modelform" ..>
         <div id="row"> 
    <input type="text" id="subject" />
    <input type="text" id="max" />
    <input type="text" id="min" />
      </div>
     <div id="row"> 
    <input type="text" id="subject" />
    <input type="text" id="max" />
    <input type="text" id="min" />
     </div>
         ............. 
    </form>}
Json(预期)

Json(上述代码的实际输出)

爪哇波乔

          public class MainPojo {

            private String name;
            private String age;            
                private Lists<marks>
                ..................
          }

          public class ModelPojo {

            private String subject;
            private String maxMarks;
            private String minMarks;

                .....................
            }
请帮我找出问题所在

谢谢。

我有

 @RequestMapping(value = "/save", method = RequestMethod.POST)
public @ResponseBody
MyEvent saveOrganization(@RequestBody Organization organization) {

    return new MyEvent('save',organization);
}
y您的mvc-servlets.xml

 <context:component-scan base-package="com.jrey.project.controllers" />
<context:annotation-config></context:annotation-config>

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
})


$(文件)
.准备好了吗(
函数(){
$(“.submit”、“form”)
.点击(
函数(){
var data=JSON
.stringify($(“#form”)
.serializeObject());
控制台日志(数据);
$
.阿贾克斯({
类型:“POST”,
url:“${pageContext.request.contextPath}/controller/organization”,
数据:数据,
数据类型:“json”,
contentType:'application/json;charset=UTF-8',
成功:功能(数据){
$(
''
+data.message
+ '')
.对话(
{
标题:“组织”,
莫代尔:是的,
按钮:{
“Aceptar”:函数(){
document.location.href=data.location;
}
}
}
);
},
});
});
});
我有

 @RequestMapping(value = "/save", method = RequestMethod.POST)
public @ResponseBody
MyEvent saveOrganization(@RequestBody Organization organization) {

    return new MyEvent('save',organization);
}
y您的mvc-servlets.xml

 <context:component-scan base-package="com.jrey.project.controllers" />
<context:annotation-config></context:annotation-config>

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
})


$(文件)
.准备好了吗(
函数(){
$(“.submit”、“form”)
.点击(
函数(){
var data=JSON
.stringify($(“#form”)
.serializeObject());
控制台日志(数据);
$
.阿贾克斯({
类型:“POST”,
url:“${pageContext.request.contextPath}/controller/organization”,
数据:数据,
数据类型:“json”,
contentType:'application/json;charset=UTF-8',
成功:功能(数据){
$(
''
+data.message
+ '')
.对话(
{
标题:“组织”,
莫代尔:是的,
按钮:{
“Aceptar”:函数(){
document.location.href=data.location;
}
}
}
);
},
});
});
});
我有

 @RequestMapping(value = "/save", method = RequestMethod.POST)
public @ResponseBody
MyEvent saveOrganization(@RequestBody Organization organization) {

    return new MyEvent('save',organization);
}
y您的mvc-servlets.xml

 <context:component-scan base-package="com.jrey.project.controllers" />
<context:annotation-config></context:annotation-config>

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
})


$(文件)
.准备好了吗(
函数(){
$(“.submit”、“form”)
.点击(
函数(){
var data=JSON
.stringify($('#形式)
  $.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
    if (o[this.name] !== undefined) {
        if (!o[this.name].push) {
            o[this.name] = [ o[this.name] ];
        }
        o[this.name].push(this.value || '');
    } else {
        o[this.name] = this.value || '';
    }
});
return o;
  <script>
$(document)
        .ready(
                function() {
                    $('.submit', '#form')
                            .click(
                                    function() {
                                        var data = JSON
                                                .stringify($('#form')
                                                        .serializeObject());
                                        console.log(data);

                                        $
                                                .ajax({
                                                    type : "POST",
                                                    url : '${pageContext.request.contextPath}/controller/organization',
                                                    data : data,
                                                    dataType : 'json',
                                                    contentType : 'application/json;charset=UTF-8',
                                                    success : function(data) {
                                                        $(
                                                                '<div>'
                                                                        + data.message
                                                                        + '</div>')
                                                                .dialog(
                                                                        {
                                                                            title : 'Organizacion',
                                                                            modal : true,
                                                                            buttons : {
                                                                                'Aceptar' : function() {
                                                                                    document.location.href = data.location;
                                                                                }
                                                                            }
                                                                        }

                                                                );
                                                    },
                                                });
                                    });
                });
     <form id="mainForm">
    <input name="name" type="text" value="Some Name">
    <input name="age" type="text" value="20">
     </form>
     <form  class="modelform">

    <input type="text" value="subject" name="subject"/>
    <input type="text" value="max" name="max"/>
    <input type="text" value="min" name="min"/>
      </form>
     <form  class="modelform">
    <input type="text" value="subject" name="subject" />
    <input type="text" value="max" name="max"/>
    <input type="text" value="min"  name="min"/>
   </form>
<script>
    var mainObject = $('#mainForm').serializeObject();
    var modelObject = [];
     $('.modelform').each(function(o){
        modelObject.push($(this).serializeObject());
    })
    mainObject.marks = modelObject;
</script>