2016-09-19 32 views
0

我目前遇到一個CodecConfigurationException與一個特定的實體。我試過爲有問題的對象添加自定義編解碼器,但這似乎並未解決問題。該錯誤信息是:當更新文檔中的對象列表時CodecConfigurationException

org.bson.codecs.configuration.CodecConfiguration:找不到類的編解碼器net.fancycow.common.ecs.entities.FancyBox

我發現了什麼奇怪的PlayerData有一個名爲Unlock的另一個自定義類(我從代碼中省略)的列表,它從不抱怨類編解碼器,但由於某種原因,它對FancyBox也是如此。在Entity類中看到的Component類只是我的各種組件實現的接口,所以FancyBox將具有各種不同的組件類型。如果任何人都可以指出我正確的方向,我可以如何解決這個問題,我真的很感激它,因爲我還沒有找到解決方案來解決這個問題。

PlayerData.class

@NoArgsConstructor 
@Entity(value = "players", noClassnameStored = true) 
public class PlayerData { 
    @Id 
    @Getter 
    private String uuid; 

    @Getter 
    private List<FancyBox> fancyBoxes = Lists.newArrayList(); 

    public PlayerData(UUID uuid) { 
     this.uuid = uuid.toString(); 
    } 
} 

FancyBox.class

@NoArgsConstructor 
public class FancyBox extends Entity { 
    /** 
    * Minimum quality of fancy boxes. 
    */ 
    public static final int MIN_QUALITY = 1; 
    /** 
    * Maximum quality of fancy boxes. 
    */ 
    public static final int MAX_QUALITY = 5; 
    /** 
    * Rarity count mapping for each quality. 
    */ 
    public static final Multimap<Integer, Entry<Rarity, Integer>> QUALITY_GENERATION = ArrayListMultimap.create(); 

    static { 
     QUALITY_GENERATION.putAll(1, Lists.newArrayList(new SimpleEntry<>(Rarity.COMMON, 3), 
       new SimpleEntry<>(Rarity.UNCOMMON, 2), 
       new SimpleEntry<>(Rarity.RARE, 1))); 
     QUALITY_GENERATION.putAll(2, Lists.newArrayList(new SimpleEntry<>(Rarity.COMMON, 2), 
       new SimpleEntry<>(Rarity.UNCOMMON, 2), 
       new SimpleEntry<>(Rarity.RARE, 1), 
       new SimpleEntry<>(Rarity.EPIC, 1))); 
     QUALITY_GENERATION.putAll(3, Lists.newArrayList(new SimpleEntry<>(Rarity.UNCOMMON, 2), 
       new SimpleEntry<>(Rarity.RARE, 2), 
       new SimpleEntry<>(Rarity.EPIC, 1), 
       new SimpleEntry<>(Rarity.LEGENDARY, 1))); 
     QUALITY_GENERATION.putAll(4, Lists.newArrayList(new SimpleEntry<>(Rarity.RARE, 2), 
       new SimpleEntry<>(Rarity.EPIC, 2), 
       new SimpleEntry<>(Rarity.LEGENDARY, 1), 
       new SimpleEntry<>(Rarity.SUPREME, 1))); 
     QUALITY_GENERATION.putAll(1, Lists.newArrayList(new SimpleEntry<>(Rarity.EPIC, 3), 
       new SimpleEntry<>(Rarity.LEGENDARY, 2), 
       new SimpleEntry<>(Rarity.SUPREME, 1))); 
    } 

    public FancyBox(@NonNull FancyBoxType type, int quality) { 
     addComponent(new FancyBoxTypeComponent(type)); 
     addComponent(new QualityComponent(quality, MAX_QUALITY)); 
     addComponent(new DateCreationComponent()); 
    } 
} 

Entity.class

public class Entity { 
    protected List<Component> components = Lists.newArrayList(); 

    public Entity addComponent(@NonNull Component component) { 
     if (!hasComponent(component.getClass())) 
      this.components.add(component); 
     return this; 
    } 

    public Entity removeComponent(@NonNull Component component) { 
     this.components.remove(component); 
     return this; 
    } 

    public Entity removeComponent(@NonNull Class<? extends Component> type) { 
     Lists.newArrayList(this.components).stream() 
       .filter(component -> component.getClass() == type) 
       .forEach(component -> this.components.remove(component)); 
     return this; 
    } 

    public <T extends Component> T getComponent(@NonNull Class<T> type) { 
     return (T) this.components.stream() 
       .filter(component -> type.isAssignableFrom(component.getClass())) 
       .findFirst() 
       .orElse(null); 
    } 

    public boolean hasComponent(@NonNull Class<?> type) { 
     return this.components.stream() 
       .filter(component -> component.getClass().equals(type)) 
       .count() > 0; 
    } 
} 

回答

1

所以經過進一步的測試和研究,我發現,它與UpdateOperations#問題在Morphia 1.2.x中添加所有。我更新到Morphia 1.3.0-SNAPSHOT並切換到UpdateOperation#push,現在一切正常。