26
26
*/
27
27
@ SdkInternalApi
28
28
public class ListQueryMarshaller implements QueryMarshaller <List <?>> {
29
+ private static final PathResolver AWS_QUERY_PATH_RESOLVER = (path , i , listTrait ) ->
30
+ listTrait .isFlattened () ?
31
+ String .format ("%s.%d" , path , i + 1 ) :
32
+ String .format ("%s.%s.%d" , path , listTrait .memberFieldInfo ().locationName (), i + 1 );
33
+ private static final PathResolver EC2_QUERY_PATH_RESOLVER = (path , i , listTrait ) -> String .format ("%s.%d" , path , i + 1 );
34
+
35
+ private static final EmptyListMarshaller AWS_QUERY_EMPTY_LIST_MARSHALLER =
36
+ (context , path ) -> context .request ().putRawQueryParameter (path , "" );
37
+ private static final EmptyListMarshaller EC2_QUERY_EMPTY_LIST_MARSHALLER = (context , path ) -> { };
29
38
30
39
private final PathResolver pathResolver ;
40
+ private final EmptyListMarshaller emptyListMarshaller ;
31
41
32
- private ListQueryMarshaller (PathResolver pathResolver ) {
42
+ private ListQueryMarshaller (PathResolver pathResolver , EmptyListMarshaller emptyListMarshaller ) {
33
43
this .pathResolver = pathResolver ;
44
+ this .emptyListMarshaller = emptyListMarshaller ;
34
45
}
35
46
36
47
@ Override
37
48
public void marshall (QueryMarshallerContext context , String path , List <?> val , SdkField <List <?>> sdkField ) {
38
- // Explicitly empty lists are marshalled as a query param with empty value in AWS/Query
49
+ // Explicitly empty lists are marshalled as a query param with empty value in AWS/Query, but not in EC2/Query
39
50
if (val .isEmpty () && !(val instanceof SdkAutoConstructList )) {
40
- context . request (). putRawQueryParameter ( path , "" );
51
+ emptyListMarshaller . marshall ( context , path );
41
52
return ;
42
53
}
43
54
for (int i = 0 ; i < val .size (); i ++) {
@@ -55,16 +66,18 @@ private interface PathResolver {
55
66
String resolve (String path , int i , ListTrait listTrait );
56
67
}
57
68
69
+ @ FunctionalInterface
70
+ private interface EmptyListMarshaller {
71
+ void marshall (QueryMarshallerContext context , String path );
72
+ }
73
+
58
74
/**
59
75
* Wires up the {@link ListQueryMarshaller} with a {@link PathResolver} that respects the flattened trait.
60
76
*
61
77
* @return ListQueryMarshaller.
62
78
*/
63
79
public static ListQueryMarshaller awsQuery () {
64
- return new ListQueryMarshaller ((path , i , listTrait ) ->
65
- listTrait .isFlattened () ?
66
- String .format ("%s.%d" , path , i + 1 ) :
67
- String .format ("%s.%s.%d" , path , listTrait .memberFieldInfo ().locationName (), i + 1 ));
80
+ return new ListQueryMarshaller (AWS_QUERY_PATH_RESOLVER , AWS_QUERY_EMPTY_LIST_MARSHALLER );
68
81
}
69
82
70
83
/**
@@ -74,6 +87,6 @@ public static ListQueryMarshaller awsQuery() {
74
87
* @return ListQueryMarshaller.
75
88
*/
76
89
public static ListQueryMarshaller ec2Query () {
77
- return new ListQueryMarshaller (( path , i , listTrait ) -> String . format ( "%s.%d" , path , i + 1 ) );
90
+ return new ListQueryMarshaller (EC2_QUERY_PATH_RESOLVER , EC2_QUERY_EMPTY_LIST_MARSHALLER );
78
91
}
79
92
}
0 commit comments