-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* For standard codecs a wrapper was added to enable to use them within polymorphic structures * when PolymorphicCodecs are registered within the chain of codecs, Polymorphia will use them when encoding polymorphic types (instead of using a reflection based codec) * PojoCodecProvider.Builder was enriched by two methods to enable excluding classes when building the domain model * fine tuning while identifying polymorphic types * type hierarchy was broken if super classes are not part of the domain model but some other superclass in the class hierarchy * adding support to register a specialized ClassResolver if neither org.springframework.spring-core or org.reflections.reflections are sufficient when resolving classes
- Loading branch information
Showing
14 changed files
with
244 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/de/bild/codec/dividedclassmodel/DividedModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package de.bild.codec.dividedclassmodel; | ||
|
||
import com.mongodb.MongoClient; | ||
import de.bild.codec.EnumCodecProvider; | ||
import de.bild.codec.PojoCodecProvider; | ||
import de.bild.codec.PolymorphicReflectionCodec; | ||
import de.bild.codec.dividedclassmodel.basemodel.BasePojo; | ||
import de.bild.codec.dividedclassmodel.nonmodel.NonModelPojo; | ||
import de.bild.codec.dividedclassmodel.submodel.SubPojoWithinModel; | ||
import org.bson.codecs.Codec; | ||
import org.bson.codecs.configuration.CodecRegistries; | ||
import org.bson.codecs.configuration.CodecRegistry; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest(classes = DividedModelTest.class) | ||
@ComponentScan(basePackages = "de.bild") | ||
public class DividedModelTest { | ||
|
||
static class Config { | ||
@Bean() | ||
public static CodecRegistry getCodecRegistry() { | ||
return CodecRegistries.fromRegistries( | ||
CodecRegistries.fromProviders( | ||
new EnumCodecProvider(), | ||
PojoCodecProvider.builder() | ||
.register(BasePojo.class.getPackage().getName()) | ||
.register(SubPojoWithinModel.class.getPackage().getName()) | ||
.build() | ||
), | ||
MongoClient.getDefaultCodecRegistry()); | ||
} | ||
} | ||
|
||
@Autowired | ||
CodecRegistry codecRegistry; | ||
|
||
@Test | ||
public void testModelClasses() { | ||
Codec<SubPojoWithinModel> subPojoWithinModelCodec = codecRegistry.get(SubPojoWithinModel.class); | ||
Assert.assertTrue(subPojoWithinModelCodec instanceof PolymorphicReflectionCodec); | ||
Codec<NonModelPojo> nonModelPojoCodec = codecRegistry.get(NonModelPojo.class); | ||
// interestingly nonModelPojoCodec will "upcast" NonModelPojo to BasePojo and a codec for BasePojo will be created | ||
Assert.assertTrue(nonModelPojoCodec instanceof PolymorphicReflectionCodec); | ||
//todo : What else do we need to check here? | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/de/bild/codec/dividedclassmodel/basemodel/BaseInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.bild.codec.dividedclassmodel.basemodel; | ||
|
||
public interface BaseInterface { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/de/bild/codec/dividedclassmodel/basemodel/BasePojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.bild.codec.dividedclassmodel.basemodel; | ||
|
||
public class BasePojo implements BaseInterface { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/de/bild/codec/dividedclassmodel/nonmodel/NonModelInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.bild.codec.dividedclassmodel.nonmodel; | ||
|
||
public interface NonModelInterface { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/java/de/bild/codec/dividedclassmodel/nonmodel/NonModelPojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.bild.codec.dividedclassmodel.nonmodel; | ||
|
||
import de.bild.codec.dividedclassmodel.basemodel.BasePojo; | ||
|
||
public class NonModelPojo extends BasePojo implements NonModelInterface { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/de/bild/codec/dividedclassmodel/nonmodel/NonModelPojoExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.bild.codec.dividedclassmodel.nonmodel; | ||
|
||
public class NonModelPojoExt extends NonModelPojo { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/java/de/bild/codec/dividedclassmodel/submodel/SubPojoWithinModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.bild.codec.dividedclassmodel.submodel; | ||
|
||
import de.bild.codec.dividedclassmodel.nonmodel.NonModelPojoExt; | ||
|
||
public class SubPojoWithinModel extends NonModelPojoExt { | ||
} |
Oops, something went wrong.