Reputation: 6970
I need to find a method to work json implementation in my gwt-project com.google.gwt.json.client
package instead of json in GWT com.google.gwt.json package
.
In my GWT project I want to use json implementation written by myself and stored in a package in my project with same path as that of GWT json package.
Files inside this packages are com.google.gwt.json.client
implemented by myself and keep in same package in my project, how to configure in project to use these packages instead of original.
Any suggestions regarding this will be appreciated.
Thanks to all..
UPDATES:
For more clarification on what I am looking for:
While parsing with JSONUtils in GWT, make parser to use JSONObject written in my project com.google.gwt.json
package, insted of GWT-json in com.google.gwt.json
package.
Upvotes: 0
Views: 142
Reputation: 9741
Sometimes it is necessary to modify certain GWT core classes because either, you need to fix an issue, or you need to add a new feature to them.
To override any GWT implementation class, for instance com.google.gwt.json.client.JSONObject
, you only have to copy and modify that class in your src folder with the same path: src/main/java/com/google/gwt/json/client/JSONObject.java
if you are using maven, src/com/google/gwt/json/client/JSONObject.java
otherwise.
The only care you need is that your src
folder is first in your classpath than the gwt sdk, with maven it is so by default. You should be aware as well that when you update the gwt version, perhaps you would need to update your implementations.
If the instances of the class you were trying to override, are created in GWT using the GWT.create()
call, you could replace the class with your own implementation with a <replace-with>
tag in your .gwt.xml
. This technique is called deferred-binding. This is not the case since JSONObject
is normally created with new
.
Finally the <super-source> tag can be used to override any class implementation in compile time. Although super-source
is designed to override jre
classes by gwt
implementations, replacing gwt with other gwt implementations works. In this case you have to put your modified classes, with the same namespace structure, in the folder pointed by the super-source
tag.
Upvotes: 2