JSON4Brwsr
From APIDesign
(→Write Your Own Provider) |
(→Write Your Own Provider) |
||
(2 intermediate revisions not shown.) | |||
Line 5: | Line 5: | ||
Can the [[Java]] to [[JSON]] mapping get any simpler than [http://bits.netbeans.org/html+java/1.2/net/java/html/json/package-summary.html net.java.html.json] package? | Can the [[Java]] to [[JSON]] mapping get any simpler than [http://bits.netbeans.org/html+java/1.2/net/java/html/json/package-summary.html net.java.html.json] package? | ||
- | I doubt. With the help of [[AnnotationProcessor]]s we remove the need to type boiler plate code. Don't bother with getters and setters, don't bother with fields. Just use the '''@Property''' annotation and the rest will be generated for you. When you need to talk to server use '''@OnReceive''' annotation and you get the result. Type-safe. Reflection-less. Effective. | + | [[I]] doubt. With the help of [[AnnotationProcessor]]s we remove the need to type boiler plate code. Don't bother with getters and setters, don't bother with fields. Just use the '''@Property''' annotation and the rest will be generated for you. When you need to talk to server use '''@OnReceive''' annotation and you get the result. Type-safe. Reflection-less. Effective. |
As the [[Twitter]] example shows, with the [[Java]] code may in fact the smaller than the same [[JavaScript]] one. | As the [[Twitter]] example shows, with the [[Java]] code may in fact the smaller than the same [[JavaScript]] one. | ||
- | == org. | + | == org.netbeans.html.json.spi == |
The above [[ClientAPI]] is accompanied with associated [[ProviderAPI]] and [[TCK]]: [http://bits.netbeans.org/html+java/1.2/org/netbeans/html/json/spi/package-summary.html HTML JSON SPI] | The above [[ClientAPI]] is accompanied with associated [[ProviderAPI]] and [[TCK]]: [http://bits.netbeans.org/html+java/1.2/org/netbeans/html/json/spi/package-summary.html HTML JSON SPI] | ||
Line 19: | Line 19: | ||
=== Write Your Own Provider === | === Write Your Own Provider === | ||
- | * Get the [http://hg.netbeans.org/html4j/ sources] and check the implementation in [http://source.apidesign.org/hg/bck2brwsr/file/f436c6bf464d/ko ko/fx and ko/bck2brwsr] modules. | + | * Get the [http://hg.netbeans.org/html4j/file/8fae1ea08618/ko4j sources] and check the implementation in [http://source.apidesign.org/hg/bck2brwsr/file/f436c6bf464d/ko ko/fx and ko/bck2brwsr] modules. |
* Implement your own [http://bits.netbeans.org/html+java/1.2/org/netbeans/html/context/spi/package-summary.html context provider] | * Implement your own [http://bits.netbeans.org/html+java/1.2/org/netbeans/html/context/spi/package-summary.html context provider] | ||
* Guarantee your [[Knockout.js]] binding (if you are attempting to do [[Knockout.js]] binding) is correct by running the [[TCK]] in [http://bits.netbeans.org/html+java/1.2/org/netbeans/html/json/tck/package-summary.html org.netbeans.html.json.tck] package. | * Guarantee your [[Knockout.js]] binding (if you are attempting to do [[Knockout.js]] binding) is correct by running the [[TCK]] in [http://bits.netbeans.org/html+java/1.2/org/netbeans/html/json/tck/package-summary.html org.netbeans.html.json.tck] package. |
Current revision
JSON is the standard API for persisting objects in current browsers. In case Java wants to get Bck2Brwsr it needs to play well with JSON. You may think there has been too many APIs to access JSON from Java created already -- one of them must fit the needs of Bck2Brwsr (and FXBrwsr). Well, it does not. The reason is that for all the previous attempts the assumption was that Java is the base and JSON is built on top of its runtime. In case of the Bck2Brwsr project the situation is up-side-down. JavaScript (and thus also JSON) is naturally supported and Java lives above it.
net.java.html.json
Can the Java to JSON mapping get any simpler than net.java.html.json package?
I doubt. With the help of AnnotationProcessors we remove the need to type boiler plate code. Don't bother with getters and setters, don't bother with fields. Just use the @Property annotation and the rest will be generated for you. When you need to talk to server use @OnReceive annotation and you get the result. Type-safe. Reflection-less. Effective.
As the Twitter example shows, with the Java code may in fact the smaller than the same JavaScript one.
org.netbeans.html.json.spi
The above ClientAPI is accompanied with associated ProviderAPI and TCK: HTML JSON SPI
Depending on the execution technology (e.g. Bck2Brwsr vs. HotSpot vs. for example TeaVM) rendering technology (Knockout.js or Angular.js, Jersey, etc.) and JSON persistence technology (e.g. native JavaScript objects vs. netscape.JSObject vs. Java wrapper like Jackson) one selects the right provider.
As a result we can use the same API and execute it in different contexts (real browser, FXBrwsr or server, or iOS or Android). Java can once again guarantee its original WORA promise.
Write Your Own Provider
- Get the sources and check the implementation in ko/fx and ko/bck2brwsr modules.
- Implement your own context provider
- Guarantee your Knockout.js binding (if you are attempting to do Knockout.js binding) is correct by running the TCK in org.netbeans.html.json.tck package.
In case of questions, ask on our mailing list bck2brwsr (at) apidesign.org