-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to serialize anonymous class and proxy
- Loading branch information
Showing
6 changed files
with
126 additions
and
6 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
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
116 changes: 116 additions & 0 deletions
116
.../github/nmorel/gwtjackson/client/advanced/ProxyAndAnonymousClassSerializationGwtTest.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,116 @@ | ||
package com.github.nmorel.gwtjackson.client.advanced; | ||
|
||
import com.github.nmorel.gwtjackson.client.GwtJacksonTestCase; | ||
import com.github.nmorel.gwtjackson.client.ObjectWriter; | ||
import com.google.gwt.core.client.GWT; | ||
import com.google.gwt.event.shared.SimpleEventBus; | ||
import com.google.web.bindery.requestfactory.shared.ProxyFor; | ||
import com.google.web.bindery.requestfactory.shared.Request; | ||
import com.google.web.bindery.requestfactory.shared.RequestContext; | ||
import com.google.web.bindery.requestfactory.shared.RequestFactory; | ||
import com.google.web.bindery.requestfactory.shared.Service; | ||
import com.google.web.bindery.requestfactory.shared.ValueProxy; | ||
|
||
/** | ||
*/ | ||
public class ProxyAndAnonymousClassSerializationGwtTest extends GwtJacksonTestCase { | ||
|
||
// RequestFactory proxy | ||
|
||
public static class RfBean { | ||
|
||
private int id; | ||
|
||
private String name; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId( int id ) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName( String name ) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
@ProxyFor( RfBean.class ) | ||
public static interface RfBeanProxy extends ValueProxy { | ||
|
||
int getId(); | ||
|
||
void setId( int id ); | ||
|
||
String getName(); | ||
|
||
void setName( String name ); | ||
} | ||
|
||
public static class RfBeanService { | ||
|
||
public void save( RfBean bean ) { | ||
|
||
} | ||
} | ||
|
||
@Service( RfBeanService.class ) | ||
public static interface ServiceContext extends RequestContext { | ||
|
||
Request<Void> save( RfBeanProxy bean ); | ||
} | ||
|
||
public static interface TestRequestFactory extends RequestFactory { | ||
|
||
ServiceContext serviceContext(); | ||
} | ||
|
||
public static interface RfBeanProxyWriter extends ObjectWriter<RfBeanProxy> {} | ||
|
||
public void testSerializationProxy() { | ||
TestRequestFactory requestFactory = GWT.create( TestRequestFactory.class ); | ||
requestFactory.initialize( new SimpleEventBus() ); | ||
|
||
ServiceContext serviceContext = requestFactory.serviceContext(); | ||
RfBeanProxy proxy = serviceContext.create( RfBeanProxy.class ); | ||
proxy.setId( 54 ); | ||
proxy.setName( "Toto" ); | ||
|
||
RfBeanProxyWriter writer = GWT.create( RfBeanProxyWriter.class ); | ||
String json = writer.write( proxy ); | ||
assertEquals( "{\"id\":54,\"name\":\"Toto\"}", json ); | ||
} | ||
|
||
//####### Anonymous class | ||
|
||
public static abstract class AbstractBean { | ||
|
||
public abstract int getId(); | ||
|
||
public abstract String getName(); | ||
} | ||
|
||
public static interface AbstractBeanWriter extends ObjectWriter<AbstractBean> {} | ||
|
||
public void testSerializationAnonymousClass() { | ||
AbstractBeanWriter writer = GWT.create( AbstractBeanWriter.class ); | ||
String json = writer.write( new AbstractBean() { | ||
@Override | ||
public int getId() { | ||
return 54; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Toto"; | ||
} | ||
} ); | ||
assertEquals( "{\"id\":54,\"name\":\"Toto\"}", json ); | ||
} | ||
|
||
} |
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