2016-09-19 4 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のaddAll私はMorphia 1.3.0-SNAPSHOTにアップデートし、UpdateOperation#pushに切り替えました。

関連する問題