-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #32 to add new ReactiveFurySerializer which implements ServerMess… (
#37) …ageBodyReader and SeverMessageBodyWriter
- Loading branch information
Showing
4 changed files
with
47 additions
and
8 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
40 changes: 40 additions & 0 deletions
40
runtime/src/main/java/io/quarkiverse/fury/ReactiveFurySerializer.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,40 @@ | ||
package io.quarkiverse.fury; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
|
||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.apache.fury.io.FuryInputStream; | ||
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo; | ||
import org.jboss.resteasy.reactive.server.spi.ServerMessageBodyReader; | ||
import org.jboss.resteasy.reactive.server.spi.ServerMessageBodyWriter; | ||
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext; | ||
|
||
public class ReactiveFurySerializer extends FurySerializer | ||
implements ServerMessageBodyReader<Object>, ServerMessageBodyWriter<Object> { | ||
@Override | ||
public boolean isReadable(final Class<?> type, final Type genericType, final ResteasyReactiveResourceInfo lazyMethod, | ||
final MediaType mediaType) { | ||
return isSupportedMediaType(mediaType) && canSerialize(type); | ||
} | ||
|
||
@Override | ||
public Object readFrom(final Class<Object> type, final Type genericType, final MediaType mediaType, | ||
final ServerRequestContext context) throws WebApplicationException, IOException { | ||
return getFury().deserialize(new FuryInputStream(context.getInputStream())); | ||
} | ||
|
||
@Override | ||
public boolean isWriteable(final Class<?> type, final Type genericType, final ResteasyReactiveResourceInfo target, | ||
final MediaType mediaType) { | ||
return isSupportedMediaType(mediaType) && canSerialize(type); | ||
} | ||
|
||
@Override | ||
public void writeResponse(final Object obj, final Type genericType, final ServerRequestContext context) | ||
throws WebApplicationException, IOException { | ||
context.getOrCreateOutputStream().write(getFury().serialize(obj)); | ||
} | ||
} |