Changeset 399
- Timestamp:
- 03/07/12 12:24:08 (12 years ago)
- Location:
- tapas
- Files:
-
- 6 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tapas/common/implementation/com/ether/JSONHelperImpl.java
r396 r399 13 13 import org.springframework.beans.factory.InitializingBean; 14 14 15 import java.lang.reflect.TypeVariable; 15 import java.util.AbstractCollection; 16 import java.util.ArrayList; 16 17 import java.util.Collection; 17 18 import java.util.Collections; 19 import java.util.List; 18 20 import java.util.Map; 19 21 … … 79 81 { 80 82 final JSONArray jsonArray = JSONArray.fromObject( json, _jsonConfig ); 81 if( beanClass.isArray() ) 83 final Class<? super T> superclass = beanClass.getSuperclass(); 84 if( superclass.isAssignableFrom( AbstractCollection.class ) ) 82 85 { 83 final Class<?> componentType = beanClass.getComponentType();84 //json.sf.net does not support Long[] or long[]85 if( Long.class.equals( componentType ) || Long.TYPE.equals( componentType ))86 final Tapas tapas = new Tapas(); 87 final List<Request> requests = new ArrayList<Request>(); 88 for( final Object jsonElement : jsonArray ) 86 89 { 87 final Integer[] integers = (Integer[]) JSONArray.toArray( jsonArray, Integer.class ); 88 if( Long.class.equals( componentType ) ) 89 { 90 final Long[] resultArray = new Long[integers.length]; 91 for( int i = 0; i < integers.length; ++i ) 92 resultArray[i] = integers[i].longValue(); 93 return (T) resultArray; 94 } 95 if( Long.TYPE.equals( componentType ) ) 96 { 97 final long[] resultArray = new long[integers.length]; 98 for( int i = 0; i < integers.length; ++i ) 99 resultArray[i] = integers[i].longValue(); 100 return (T) resultArray; 101 } 90 final Request request = fromJSON( (JSON) jsonElement, Request.class ); 91 requests.add( request ); 102 92 } 103 return (T) JSONArray.toArray( jsonArray, componentType ); 93 tapas.setRequests( requests ); 94 return (T) tapas; 104 95 } 105 if( beanClass.isAssignableFrom( Collection.class ) ) 106 { 107 final TypeVariable<Class<T>>[] typeParameters = beanClass.getTypeParameters(); 108 if( null == typeParameters || typeParameters.length != 1 || null == typeParameters[0] ) 109 return (T) JSONArray.toCollection( jsonArray ); 110 return (T) JSONArray.toCollection( jsonArray, typeParameters[0].getGenericDeclaration() ); 111 } 96 // 97 // if( beanClass.isArray() ) 98 // { 99 // final Class<?> componentType = beanClass.getComponentType(); 100 // //json.sf.net does not support Long[] or long[] 101 // if( Long.class.equals( componentType ) || Long.TYPE.equals( componentType ) ) 102 // { 103 // final Integer[] integers = (Integer[]) JSONArray.toArray( jsonArray, Integer.class ); 104 // if( Long.class.equals( componentType ) ) 105 // { 106 // final Long[] resultArray = new Long[integers.length]; 107 // for( int i = 0; i < integers.length; ++i ) 108 // resultArray[i] = integers[i].longValue(); 109 // return (T) resultArray; 110 // } 111 // if( Long.TYPE.equals( componentType ) ) 112 // { 113 // final long[] resultArray = new long[integers.length]; 114 // for( int i = 0; i < integers.length; ++i ) 115 // resultArray[i] = integers[i].longValue(); 116 // return (T) resultArray; 117 // } 118 // } 119 // return (T) JSONArray.toArray( jsonArray, componentType ); 120 // } 121 // if( beanClass.isAssignableFrom( Collection.class ) ) 122 // { 123 // final TypeVariable<Class<T>>[] typeParameters = beanClass.getTypeParameters(); 124 // if( null == typeParameters || typeParameters.length != 1 || null == typeParameters[0] ) 125 // return (T) JSONArray.toCollection( jsonArray ); 126 // return (T) JSONArray.toCollection( jsonArray, typeParameters[0].getGenericDeclaration() ); 127 // } 112 128 } 113 129 final JSONObject jsonObject = JSONObject.fromObject( json, _jsonConfig ); -
tapas/web/init_script.jsp
r396 r399 31 31 requestCreateXML: function() 32 32 { 33 var bob = new Object(); 34 bob.input1 = "eee"; 35 bob.input2 = "rr"; 36 var jsonBob = $.toJSON( bob ); 37 33 38 var jsonFormXml = this.serializeFormXMLToJson(); 34 39 if( jsonFormXml ) 35 40 $.ajax( { 36 url: "project?methodName=createUserRequest&jsonFormX ML=" + jsonFormXml,41 url: "project?methodName=createUserRequest&jsonFormXml=" + jsonBob + "&jsonTapas=" + jsonFormXml, 37 42 success:jQuery.proxy( this.handleCreateXML, this ) 38 43 } ); … … 56 61 serializeFormXMLToJson: function() 57 62 { 58 var formXML = new Object(); 59 formXML.input1 = $( "#1" ).val(); 60 formXML.input2 = $( "#2" ).val(); 63 var formXML = new Array(); 64 var requestXML = new Object(); 65 66 var preference = new Object(); 67 preference.format = $( "#1" ).val(); 68 preference.rayleigh_extinction = $( "#2" ).val(); 69 preference.h2o_extinction = "h2o_extinction"; 70 preference.o3_extinction = "o3_extinction"; 71 preference.o2_extinction = "o2_extinction"; 72 preference.co2_extinction = "co2_extinction"; 73 74 var observation = new Object(); 75 observation.date = "2012-02-24"; 76 77 requestXML.preference = preference; 78 requestXML.observation = observation; 79 requestXML.atmosphere = "atmosphereZZZZ"; 80 81 formXML[0] = requestXML; 82 61 83 return $.toJSON( formXML ); 62 84 } -
tapas/web/src/com/ether/Controller.java
r396 r399 5 5 import com.ether.annotation.ParamName; 6 6 import com.ether.annotation.UseJSON; 7 import com.ether.Tapas; 7 8 import net.sf.json.JSONObject; 8 9 import org.apache.commons.logging.Log; … … 37 38 /** *********************************************************** **/ 38 39 @ControllerMethod(jsonResult = true) 39 public JSONObject createUserRequest( @ParamName("jsonFormXML") @Mandatory @UseJSON final FormXML jsonFormXML ) 40 public JSONObject createUserRequest( @ParamName("jsonFormXml") @Mandatory @UseJSON final FormXML jsonFormXML, 41 @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas jsonTapas ) 40 42 throws ServiceException 41 43 {
Note: See TracChangeset
for help on using the changeset viewer.