<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(已弃用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
                    <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>