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

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

        创建列表的替代方法&lt;MyObject&gt;在 @DynamoDBTable 中不使用 dynam

        Alternate way to create Listlt;MyObjectgt; in @DynamoDBTable without using dynamodbmarshalling (deprecated)(创建列表的替代方法lt;MyObjectgt;在 @DynamoDBTable 中不使用 dynamodbmarshalling(已弃用))
        <legend id='bAMjw'><style id='bAMjw'><dir id='bAMjw'><q id='bAMjw'></q></dir></style></legend>

          • <tfoot id='bAMjw'></tfoot>
              <bdo id='bAMjw'></bdo><ul id='bAMjw'></ul>

                    <tbody id='bAMjw'></tbody>

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

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

                  本文介绍了创建列表的替代方法&lt;MyObject&gt;在 @DynamoDBTable 中不使用 dynamodbmarshalling(已弃用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我通过创建MyCustomMarshaller来关注此处.

                  MyCustomMarshaller

                  public class MyCustomMarshaller implements DynamoDBMarshaller<List<DemoClass>> {
                  
                      private static final ObjectMapper mapper = new ObjectMapper();
                      private static final ObjectWriter writer = mapper.writer();
                  
                      @Override
                      public String marshall(List<DemoClass> obj) {
                  
                          try {
                              return writer.writeValueAsString(obj);
                          } catch (JsonProcessingException e) {
                              throw failure(e,
                                      "Unable to marshall the instance of " + obj.getClass()
                                              + "into a string");
                          }
                      }
                  
                      @Override
                      public List<DemoClass> unmarshall(Class<List<DemoClass>> clazz, String json) {
                          final CollectionType
                                  type =
                                  mapper.getTypeFactory().constructCollectionType(List.class, DemoClass.class);
                          try {
                              return mapper.readValue(json, type);
                          } catch (Exception e) {
                              throw failure(e, "Unable to unmarshall the string " + json
                                      + "into " + clazz);
                          }
                      }
                  }
                  

                  我的 dynamoDb 类

                  @DynamoDBAttribute
                  @DynamoDBMarshalling(marshallerClass = MyCustomMarshaller.class)
                  List<DemoClass> Object;
                  

                  DemoClass

                  public class DemoClass {
                  
                      String name;
                  
                      int id;
                  
                  }
                  

                  所有代码都运行良好.事实是

                  All the codes were working great.By the thing is

                  com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshalling 是已弃用

                  com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshalling is deprecated

                  那么如何在不使用此 dynamoDBmarshalling 的情况下更改我的代码?

                  So how can I change my code without using this dynamoDBmarshalling?

                  提前致谢,
                  周杰伦

                  Thanks in Advance,
                  Jay

                  推荐答案

                  是的,你应该使用 DynamoDBTypeConverter

                  您可以从这里

                  为了完整起见,这里是我在链接答案中使用的示例

                  For completeness here is the example I used on the linked answer

                  // Model.java
                  @DynamoDBTable(tableName = "...")
                  public class Model {
                    private String id;
                    private List<MyObject> objects;
                  
                    public Model(String id, List<MyObject> objects) {
                      this.id = id;
                      this.objects = objects;
                    }
                  
                    @DynamoDBHashKey(attributeName = "id")
                    public String getId() { return this.id; }
                    public void setId(String id) { this.id = id; }
                  
                    @DynamoDBTypeConverted(converter = MyObjectConverter.class)
                    public List<MyObject> getObjects() { return this.objects; }
                    public void setObjects(List<MyObject> objects) { this.objects = objects; }
                  }
                  

                  -

                  public class MyObjectConverter implements DynamoDBTypeConverter<String, List<MyObject>> {
                  
                      @Override
                      public String convert(List<Object> objects) {
                          //Jackson object mapper
                          ObjectMapper objectMapper = new ObjectMapper();
                          try {
                              String objectsString = objectMapper.writeValueAsString(objects);
                              return objectsString;
                          } catch (JsonProcessingException e) {
                              //do something
                          }
                          return null;
                      }
                  
                      @Override
                      public List<Object> unconvert(String objectssString) {
                          ObjectMapper objectMapper = new ObjectMapper();
                          try {
                              List<Object> objects = objectMapper.readValue(objectsString, new TypeReference<List<Object>>(){});
                              return objects;
                          } catch (JsonParseException e) {
                              //do something
                          } catch (JsonMappingException e) {
                              //do something
                          } catch (IOException e) {
                              //do something
                          }
                          return null;
                      }
                  }
                  

                  这篇关于创建列表的替代方法&lt;MyObject&gt;在 @DynamoDBTable 中不使用 dynamodbmarshalling(已弃用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tbody id='kjywx'></tbody>

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

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

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