2016-08-09 10 views
0

ここでは、JAVAオブジェクトにマップしようとしているデータ構造はありますが、groupIdプロパティを適切にマップする方法を理解できません。 誰かがそれがどのように行われたか教えてもらえますか? [roupWithGroupId firebase datastructureFirebaseデータ構造からJAVAオブジェクトへのマッピング時に認識されないフィールド

Caused by: java.lang.IllegalArgumentException: Unrecognized field "1" (class firebasetest.model.GroupWithGroupId), not marked as ignorable (6 known properties: , "lastGroupId", "hourLimit", "maxLimit", "minLimit", "groupId", "actualLimit"]) 
    08-09 19:04:43.130 8259-8259/firebasetest I/System.out:  at [Source: N/A; line: -1, column: -1] (through reference chain: firebasetest.model.GroupWithGroupId["1"]) 
08-09 19:04:43.130 8259-8259/firebasetest I/System.out:  at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2615) 

とJavaオブジェクト:あなたのクラスから@IgnoreExtraPropertiesが欠落しているよう

public class GroupWithGroupId { 
     public long actualLimit, hourLimit,lastGroupId,maxLimit,minLimit; 
     public Map<String, Object> groupId = new HashMap<>(); 
     private GroupWithGroupId(){} 

     public GroupWithGroupId(final long actualLimit, final long hourLimit, final long lastGroupId, final long maxLimit, final long minLimit) { 
      this.actualLimit = actualLimit; 
      this.hourLimit = hourLimit; 
      this.lastGroupId = lastGroupId; 
      this.maxLimit = maxLimit; 
      this.minLimit = minLimit; 
     } 

     @Exclude 
     public Map<String, Object> toMap() { 
      HashMap<String, Object> result = new HashMap<>(); 
      result.put("actualLimit", actualLimit); 
      result.put("hourLimit", hourLimit); 
      result.put("lastGroupId", lastGroupId); 
      result.put("minLimit", minLimit); 
      result.put("maxLimit", maxLimit); 
      result.put("groupId", groupId); 
      return result; 
     } 
} 

答えて

0

が見えます。

@IgnoreExtraProperties 
public class User { 

     @IgnoreExtraProperties 
     public class Location { 

       public Double latitude; 
       public Double longitude; 

       public Location() {} 

       public Location(Double latitude, Double longitude) { 
         this.latitude = latitude; 
         this.longitude = longitude; 
       } 

       @Exclude 
       public Map<String, Object> toMap() { 
         HashMap<String, Object> result = new HashMap<>(); 
         result.put("latitude", latitude); 
         result.put("longitude", longitude); 
         return result; 
       } 
     } 

     public String firstName; 
     public String lastName; 
     public String email; 
     public String phone; 
     public Location location; 
     public Date lastUpdated; 
     public Date signUpDate; 

     public User() {} 

     public User(String firstName, String lastName, String email) { 
       this.firstName = firstName; 
       this.lastName = lastName; 
       this.email = email; 
       this.lastUpdated = new Date(); 
       this.signUpDate = new Date(); 
     } 

     @Exclude 
     public Map<String, Object> toMap() { 
       HashMap<String, Object> result = new HashMap<>(); 
       result.put("firstName", firstName); 
       result.put("lastName", lastName); 
       result.put("email", email); 
       result.put("phone", phone); 
       result.put("location", location.toMap()); 
       result.put("lastUpdated", lastUpdated); 
       result.put("signUpDate", signUpDate); 
       return result; 
     } 

} 
+0

ありがとうございました。それは助けになりましたが、私は適切なfuntcioningのために少しtoMap()関数を修正しなければなりませんでした。以下の私の解決策を見てください – SzabK

0

私はtoMap()GroupWithoutGroupIdで機能を変更する必要がありましたし、今では正常に動作します(!私はこれをテストしていません注意してうまくいけば、それは役立ちます)

は、次のようなものを試してみてください!

@IgnoreExtraProperties 
public class GroupWithoutGroupId { 
    public long actualLimit, hourLimit,lastGroupId,maxLimit,minLimit; 
    public GroupID groupID; 
    public String groupIDkey; 

    private GroupWithoutGroupId(){} 
    public GroupWithoutGroupId(final long actualLimit, final long hourLimit, final long lastGroupId, final long maxLimit, final long minLimit) { 
     this.actualLimit = actualLimit; 
     this.hourLimit = hourLimit; 
     this.lastGroupId = lastGroupId; 
     this.maxLimit = maxLimit; 
     this.minLimit = minLimit; 
    } 

    @Exclude 
    public Map<String, Object> toMap() { 
     HashMap<String, Object> result = new HashMap<>(); 
     result.put("actualLimit", actualLimit); 
     result.put("hourLimit", hourLimit); 
     result.put("lastGroupId", lastGroupId); 
     result.put("minLimit", minLimit); 
     result.put("maxLimit", maxLimit); 
     result.put(groupIDkey, groupID.toMap()); 
     return result; 
    } 

    @IgnoreExtraProperties 
    public class GroupID { 
     public long sum; 
     public Map<String, Object> users = new HashMap<>(); 

     public GroupID(){} 
     public GroupID(final long sum, final Map<String, Object> users) { 
      this.sum = sum; 
      this.users = users; 
     } 

     @Exclude 
     public Map<String, Object> toMap() { 
      HashMap<String, Object> result = new HashMap<>(); 
      result.put("sum", sum); 
      result.put("users", users); 


     return result; 
      } 
... 
関連する問題