-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
substitute ObjectMapperModifier by SciJavaJSONSerializer
- Loading branch information
Showing
5 changed files
with
72 additions
and
82 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/net/imagej/server/json/JsonSerializerAdapter.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,29 @@ | ||
package net.imagej.server.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
|
||
import java.io.IOException; | ||
|
||
class JsonSerializerAdapter<T> extends StdSerializer<T> { | ||
|
||
private SciJavaJSONSerializer<T> serializedDelegate; | ||
|
||
public JsonSerializerAdapter( | ||
SciJavaJSONSerializer<T> serializedDelegate) | ||
{ | ||
super(serializedDelegate.handleType()); | ||
this.serializedDelegate = serializedDelegate; | ||
} | ||
|
||
|
||
@Override | ||
public void serialize(T value, JsonGenerator gen, | ||
SerializerProvider provider) throws IOException | ||
{ | ||
serializedDelegate.serialize(value, gen, provider); | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/imagej/server/json/SciJavaJSONSerializer.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,32 @@ | ||
|
||
package net.imagej.server.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
import java.io.IOException; | ||
|
||
import org.scijava.plugin.SciJavaPlugin; | ||
|
||
public interface SciJavaJSONSerializer<T> extends SciJavaPlugin | ||
|
||
{ | ||
|
||
void serialize(T value, JsonGenerator gen, | ||
SerializerProvider serializers) | ||
throws IOException; | ||
|
||
Class<T> handleType(); | ||
|
||
default boolean isSupportedBy(Class<?> desiredClass) { | ||
return handleType().isAssignableFrom(desiredClass); | ||
} | ||
|
||
default public void register(ObjectMapper mapper) { | ||
SimpleModule mod = new SimpleModule(); | ||
mod.addSerializer(new JsonSerializerAdapter<>(this)); | ||
mapper.registerModule(mod); | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
src/main/java/net/imagej/server/modifiers/ObjectMapperModifier.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/net/imagej/server/modifiers/SerializerModifier.java
This file was deleted.
Oops, something went wrong.
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