-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
485f498
commit de8b33d
Showing
11 changed files
with
96 additions
and
30 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
23 changes: 23 additions & 0 deletions
23
...anache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdDeserializer.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,23 @@ | ||
package io.quarkus.mongodb.panache.jackson; | ||
|
||
import java.io.IOException; | ||
|
||
import org.bson.types.ObjectId; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
public class ObjectIdDeserializer extends JsonDeserializer<ObjectId> { | ||
|
||
@Override | ||
public ObjectId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) | ||
throws IOException, JsonProcessingException { | ||
String value = jsonParser.getValueAsString(); | ||
if (value != null) { | ||
return new ObjectId(value); | ||
} | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...-panache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectIdSerializer.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,20 @@ | ||
package io.quarkus.mongodb.panache.jackson; | ||
|
||
import java.io.IOException; | ||
|
||
import org.bson.types.ObjectId; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
public class ObjectIdSerializer extends JsonSerializer<ObjectId> { | ||
|
||
@Override | ||
public void serialize(ObjectId objectId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) | ||
throws IOException { | ||
if (objectId != null) { | ||
jsonGenerator.writeString(objectId.toString()); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...anache/runtime/src/main/java/io/quarkus/mongodb/panache/jackson/ObjectMapperProducer.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,28 @@ | ||
package io.quarkus.mongodb.panache.jackson; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
|
||
import org.bson.types.ObjectId; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
/** | ||
* This ObjectMapperProducer will produce an ObjectMapper that will override the default one from resteasy-jackson. | ||
*/ | ||
@ApplicationScoped | ||
public class ObjectMapperProducer { | ||
|
||
@Singleton | ||
@Produces | ||
public ObjectMapper objectMapper() { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
SimpleModule module = new SimpleModule("ObjectIdModule"); | ||
module.addSerializer(ObjectId.class, new ObjectIdSerializer()); | ||
module.addDeserializer(ObjectId.class, new ObjectIdDeserializer()); | ||
objectMapper.registerModule(module); | ||
return objectMapper; | ||
} | ||
} |
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