Skip to content

Commit

Permalink
correct jdk 1.8 compiler error
Browse files Browse the repository at this point in the history
  • Loading branch information
webermich committed Aug 29, 2019
1 parent a054a4c commit 9e0d42c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
20 changes: 5 additions & 15 deletions src/main/java/de/bild/codec/ObjectCodec.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
package de.bild.codec;

import static org.bson.assertions.Assertions.notNull;
import org.bson.*;
import org.bson.codecs.*;
import org.bson.codecs.configuration.CodecRegistry;

import java.util.UUID;

import org.bson.BsonBinarySubType;
import org.bson.BsonReader;
import org.bson.BsonType;
import org.bson.BsonWriter;
import org.bson.Transformer;
import org.bson.codecs.BsonTypeClassMap;
import org.bson.codecs.BsonTypeCodecMap;
import org.bson.codecs.Codec;
import org.bson.codecs.Decoder;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;
import org.bson.codecs.IterableCodec;
import org.bson.codecs.configuration.CodecRegistry;
import static org.bson.assertions.Assertions.notNull;


/**
Expand Down Expand Up @@ -57,7 +47,7 @@ public void encode(final BsonWriter writer, final T value, final EncoderContext
return;
}

final Codec<T> encoder = registry.get(value.getClass().asSubclass(clazz));
final Codec encoder = registry.get(value.getClass());
if (encoder == null) {
throw new UnsupportedOperationException(value.getClass().toString());
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/de/bild/codec/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public static CodecRegistry getCodecRegistry() {
return CodecRegistries.fromRegistries(
CodecRegistries.fromProviders(
new EnumCodecProvider(),
PojoCodecProvider.builder().register(BaseTest.class).build()
PojoCodecProvider.builder().register(BaseTest.class).build(),
new ObjectCodecProvider()
),
MongoClient.getDefaultCodecRegistry()
);
Expand All @@ -132,6 +133,7 @@ public static CodecRegistry getCodecRegistry() {
CodecRegistry codecRegistry;

static class BasePojo {
Object someObject;
String aString;
float aPrimitiveFloat;
int aPrimitiveInt;
Expand Down Expand Up @@ -176,6 +178,7 @@ public boolean equals(Object o) {
if (!(o instanceof BasePojo)) return false;

BasePojo basePojo = (BasePojo) o;
if (someObject != null ? !someObject.equals(basePojo.someObject) : basePojo.someObject != null) return false;

if (Float.compare(basePojo.aPrimitiveFloat, aPrimitiveFloat) != 0) return false;
if (aPrimitiveInt != basePojo.aPrimitiveInt) return false;
Expand Down Expand Up @@ -243,6 +246,7 @@ public int hashCode() {
result = 31 * result + (aShort != null ? aShort.hashCode() : 0);
result = 31 * result + (aByte != null ? aByte.hashCode() : 0);
result = 31 * result + (aDouble != null ? aDouble.hashCode() : 0);
result = 31 * result + (someObject != null ? someObject.hashCode() : 0);
result = 31 * result + Arrays.hashCode(strings);
result = 31 * result + Arrays.hashCode(primitiveFloats);
result = 31 * result + Arrays.hashCode(primitiveInts);
Expand Down Expand Up @@ -293,6 +297,7 @@ static class IntegerType extends Base<Integer> {
@Test
public void basicTest() {
BasePojo basePojo = new BasePojo();
basePojo.someObject = STRING;
basePojo.aString = STRING;
basePojo.aPrimitiveByte = PRIMITIVE_BYTE;
basePojo.aPrimitiveChar = PRIMITIVE_CHAR;
Expand Down

0 comments on commit 9e0d42c

Please sign in to comment.