<tfoot id='g6PJk'></tfoot>
  • <legend id='g6PJk'><style id='g6PJk'><dir id='g6PJk'><q id='g6PJk'></q></dir></style></legend>

      • <bdo id='g6PJk'></bdo><ul id='g6PJk'></ul>

      <small id='g6PJk'></small><noframes id='g6PJk'>

        <i id='g6PJk'><tr id='g6PJk'><dt id='g6PJk'><q id='g6PJk'><span id='g6PJk'><b id='g6PJk'><form id='g6PJk'><ins id='g6PJk'></ins><ul id='g6PJk'></ul><sub id='g6PJk'></sub></form><legend id='g6PJk'></legend><bdo id='g6PJk'><pre id='g6PJk'><center id='g6PJk'></center></pre></bdo></b><th id='g6PJk'></th></span></q></dt></tr></i><div id='g6PJk'><tfoot id='g6PJk'></tfoot><dl id='g6PJk'><fieldset id='g6PJk'></fieldset></dl></div>

        Struts2 + Json 项目的序列化

        时间:2023-09-25
        <legend id='uINH4'><style id='uINH4'><dir id='uINH4'><q id='uINH4'></q></dir></style></legend>

          1. <small id='uINH4'></small><noframes id='uINH4'>

                <tbody id='uINH4'></tbody>
              <tfoot id='uINH4'></tfoot>
              <i id='uINH4'><tr id='uINH4'><dt id='uINH4'><q id='uINH4'><span id='uINH4'><b id='uINH4'><form id='uINH4'><ins id='uINH4'></ins><ul id='uINH4'></ul><sub id='uINH4'></sub></form><legend id='uINH4'></legend><bdo id='uINH4'><pre id='uINH4'><center id='uINH4'></center></pre></bdo></b><th id='uINH4'></th></span></q></dt></tr></i><div id='uINH4'><tfoot id='uINH4'></tfoot><dl id='uINH4'><fieldset id='uINH4'></fieldset></dl></div>
                <bdo id='uINH4'></bdo><ul id='uINH4'></ul>

                1. 本文介绍了Struts2 + Json 项目的序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下课程:

                  public class Student {
                      private Long id  ;
                      private String firstName;
                      private String lastName;
                  private Set<Enrollment> enroll = new HashSet<Enrollment>();
                  //Setters and getters
                  }
                  
                  public class Enrollment {
                      private Student student;
                      private Course course;
                      Long enrollId;
                  
                  //Setters and Getters
                  }
                  

                  我有 Struts2 控制器,我想只返回 Class Student 的序列化实例.

                  I have Struts2 controller and I would like to to return Serialized instance of Class Student only.

                  @ParentPackage("json-default")
                  public class JsonAction extends ActionSupport{
                  
                  private Student student;
                  
                  @Autowired
                  DbService dbService;
                  
                  public String populate(){
                      return "populate";
                  }
                  
                  @Action(value="/getJson", results = {
                          @Result(name="success", type="json")})
                  public String test(){
                      student =  dbService.getSudent(new Long(1));
                      return "success";
                  }
                  
                  @JSON(name="student")
                  public Student getStudent() {
                      return student;
                  }
                  public void setStudent(Student student) {
                      this.student = student;
                  }
                  
                  }
                  

                  它返回给我所有子类的可序列化学生对象,但我希望只有学生对象而不返回哈希集.如何告诉 Struts 只序列化对象?我确实启用了延迟加载,并且 hashset 作为代理类返回.

                  It returns me the serializable student object with all sub classes, but I would like to have only student object without the hashset returned . How can I tell Struts to serialize only the object? I do have Lazy loading enabled and hashset is returned as proxy class.

                  推荐答案

                  在此处查看答案,其中显示了包含和排除属性的使用.我不认为该示例清楚地显示了排除嵌套对象,但是我已将其用于此目的.如果您仍有问题,我将发布一个正则表达式来证明这一点.

                  See the answer here which shows the use of include and exclude properties. I don't think the example clearly shows excluding nested objects however I have used it for this purpose. If you still have issues I'll post a regex which will demonstrate this.

                  Struts 2 中的 Json 插件问题

                  编辑:这是一个在注释中使用排除属性的示例,它阻止了嵌套成员的序列化:

                  Edit: Here is an example of using exclude properties in an annotation which blocks the serialization of a nested member:

                  @ParentPackage("json-default")
                  @Result(type = "json", params = {
                          "excludeProperties",
                          "^inventoryHistory\[\d+\]\.intrnmst, selectedTransactionNames, transactionNames"
                      })
                  public class InventoryHistoryAction extends ActionSupport {
                  ...
                  

                  inventoryHistory 是 JPA 实体对象的 InventoryHistory 类型,intrnmst 引用另一个表,但由于延迟加载,如果它被序列化,当操作被 JSON 序列化时会导致异常,因此添加了 exclude 参数来防止这种情况.

                  inventoryHistory is of type InventoryHistory a JPA entity object, intrnmst references another table but because of lazy loading if it were serialized it would cause an Exception when the action is JSON serialized for this reason the exclude parameter has been added to prevent this.

                  注意

                  \ 
                  

                  对于每个 字符都是必需的,因此单个 只会在需要两个的 xml 中使用,因为要转义以便正确解析字符串.

                  is required for each character, so a single would only be used in the xml where two are required because of escaping for the string to be parsed right.

                  这篇关于Struts2 + Json 项目的序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何显示所有可用的 Struts2 动作? 下一篇:java - 如何在java strust2中将jsp上显示的表格导出为pdf

                  相关文章

                2. <i id='hrVJv'><tr id='hrVJv'><dt id='hrVJv'><q id='hrVJv'><span id='hrVJv'><b id='hrVJv'><form id='hrVJv'><ins id='hrVJv'></ins><ul id='hrVJv'></ul><sub id='hrVJv'></sub></form><legend id='hrVJv'></legend><bdo id='hrVJv'><pre id='hrVJv'><center id='hrVJv'></center></pre></bdo></b><th id='hrVJv'></th></span></q></dt></tr></i><div id='hrVJv'><tfoot id='hrVJv'></tfoot><dl id='hrVJv'><fieldset id='hrVJv'></fieldset></dl></div>

                    <bdo id='hrVJv'></bdo><ul id='hrVJv'></ul>

                      <legend id='hrVJv'><style id='hrVJv'><dir id='hrVJv'><q id='hrVJv'></q></dir></style></legend>

                      <tfoot id='hrVJv'></tfoot>
                    1. <small id='hrVJv'></small><noframes id='hrVJv'>