Comments (14)
Hello, thanks for your interest into my project :)
From what I understand, it seems you have no generator inside your framework. When you do a request, you explicit tell the class of the parameter and return types. The Requestor will then look for Serializer/Deserializer into some kind of Map I guess ?
What you can do is defining some new interfaces like GwtJacksonSerializer<T> extends Serializer<T>
and GwtJacksonDeserializer<T> extends Deserializer<T>
.
An user who wants to serialize a new type can create an interface MyTypeSerializer extends GwtJacksonSerializer<MyType>
and call a new method on Requestor : registerSerializer(Class<T> type, Class<S extends GwtJacksonSerializer<T>> serializerClass)
. The requestor creates the serializer using GWT.create(serializerClass).
Once you have that, you just have to make a simple generator that will create an implementation containing :
- an inner interface
InnerMyTypeSerializer extends ObjectWriter<MyType>
, - a call to GWT.create on this inner interface
- the implementation of the serialize method that just delegate the operation to the inner interface
If you have something else in mind, I can help :)
from gwt-jackson.
From what I understand, it seems you have no generator inside your framework. When you do a request, you explicit tell the class of the parameter and return types. The Requestor will then look for Serializer/Deserializer into some kind of Map I guess ?
Correct! The de/serializer is selected by matching both type (class) and content-type.
An user who wants to serialize a new type can create an
interface MyTypeSerializer extends GwtJacksonSerializer<MyType>
I really would like to skip this step! You were clear about how to implement the generator, and I think this is the way to go. But don't you know if it's possible to, instead of declaring a new interface, just putting some annotation on top of model class, achieve the binding to the generator?
I mean, is it possible to bind some generator by resorting to annotations instead of types (interfaces)? (This is a GWT question =P)
I imagine one would put an annotation just telling the content-type patterns to handle on serializing and deserializing.
@GwtJacksonSerialize({"*/json", "*/javascript"})
@GwtJacksonDeserialize({"*/json", "*/javascript"})
public class Book { ... }
Indeed, @GwtJacksonSerialize
and @GwtJacksonDeserialize
would have application/json
as default content-type pattern.
I find this way more interesting. What do you think? Is it possible?
from gwt-jackson.
I mean, is it possible to bind some generator by resorting to annotations instead of types (interfaces)?
Yes, it's possible: http://stackoverflow.com/questions/10521016/is-it-possible-to-find-all-classes-annotated-with-myannotation-using-a-gwt-gene :)
But, how would I integrate with the Requestor? Maybe I would need to create something inside the Requestor with Defferred Binding.
from gwt-jackson.
I was going to say it's possible :)
You could have an internal interface like DefaultSerdesFactory with just a getter for serializer and deserializer maps. Your requestor calls GWT.create on it and initalisze its map with those. If the user gives other serializer, it overrides the default ones.
The generator of DefaultSerdesFactory has just to iterate through all types looking for annotations and initalize the map.
I don't know if there are any drawbacks using this method. I'm not sure how it will work with the incremental compilation coming soon if your generator has to loop through all type everytime. Could be a good question to ask on GWT forum!
from gwt-jackson.
Nice! Thanks for the insights!
from gwt-jackson.
Forgot something, the generator also have to generate inner interfaces extending gwt-jackson interface for every type. You could skip the GwtJacksonSerializer by creating anonymous class that directly delegate to gwt-jackson.
If I'm not clear, I can give an example :p
from gwt-jackson.
Sure. Otherwise I couldn't use gwt-jackson's generators.
from gwt-jackson.
Good news. It worked like a charm! :)
I'm still improving the code, and will publish the solution ASAP,
I would like your opinion about the annotation name. I'm using GwtJacksonSerialize and GwtJacksonDeserialize. Is it good enough? Do you suggest any other?
ps: I'm not sure what is the best approach to test generators. How do you do it?
from gwt-jackson.
I'm glad it worked :)
It's a bit long maybe and too close to the implementation. If you want to change the library or add an other, maybe you should pick a more generic name like JsonSerialize and JsonDeserialize. These way, it will be transparent to the user if you change anything in the implementation.
To test them, I just use the GwtTestCase and test the generated implementation.
from gwt-jackson.
I also looked at your project. To add your callback, maybe you should decompose in two methods onSuccess() and onFailure(). This way, your callbacks only have one method and are good candidates for FunctionalInterface and lambda.
from gwt-jackson.
Hum .. thanks for the insights!
I've found the name too long too. I'll accept your suggestion about the annotation names.
As to the callbacks, yeah, I'm planning to change the callbacks to one method callbacks only. Initially, I thought it would be good to rely on GWT default types, but now I don't see this as so important, specially because I'm reusing simple types as callbacks.
Actually, I plan to implement a general purpose Deferred API (in -Core) and use it on Turbo GWT HTTP. I miss one for GWT.
from gwt-jackson.
Additionally, I will create another repo for this specific integration. About the repo's name, would you think "turbogwt-jackson" could cause some confusion? If so, I was thinking about "turbogwt-gj".
from gwt-jackson.
It could if people think you are also developping a jackson serialization mechanism.
Maybe add a -impl or "turbogwt-http-gwt-jackson" :D I don't know :)
As long as you specify in the readme it's the integration of gwt-jackson inside your library, you can pick the name you like I think!
from gwt-jackson.
I guess I'll let "turbogwt-gwt-jackson"
from gwt-jackson.
Related Issues (20)
- HashMap <SimplePojo, Set <Integer>> ...does not serialize into Json HOT 2
- No source code is available for type com.fasterxml.jackson.databind.ObjectMapper; did you forget to inherit a required module? HOT 3
- Support for java.util.Optional HOT 1
- Expected a string but was BEGIN_OBJECT at line 1 column 2 HOT 1
- Please REVERT the dependency on Jackson 2.9.*, Jackson 2.9.* is NOT compatible with GWT. HOT 2
- Support for @JsonCreator(mode = Mode.DELEGATING)
- Custom deserializer compilation error
- Getter returning Optional<T> of nullable T causing compilation error HOT 2
- GWT 2.6.1 + GwtJackson 0.15.3 HOT 3
- JsonSerializationContext.Builder override not working as expected
- Error:GWT Compiler: No source code is available for type com.fasterxml.jackson.annotation.JsonTypeInfo.As; did you forget to inherit a required module?
- JsonTypeInfo defaultImpl attribute not working HOT 1
- Update jackson dependency to 2.9.8
- Update javapoet dependency to 1.11.1
- Support for JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE
- Annotations on Java8 default interface are ignored HOT 1
- Can't figure out the stackoverflow I am getting
- More (de)serialization customization (JsonFilter or equivalent)
- Double.NaN / NEGATIVE_INFINITY / POSITIVE_INFINITY - Numeric values must be finite, but was
- Many compile problems
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gwt-jackson.