-
Notifications
You must be signed in to change notification settings - Fork 870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logic to handle number acceptors #5813
base: master
Are you sure you want to change the base?
Changes from 6 commits
da03c17
8b6f2ae
47eb17c
329a4ce
353015e
cd55716
77382f8
fe76401
d9f817e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "feature", | ||
"category": "AWS SDK for Java v2 - waiters", | ||
"contributor": "", | ||
"description": "adding any number support for waiters' path matchers" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.jr.ob.JSON; | ||
import com.fasterxml.jackson.jr.stree.JacksonJrsTreeCodec; | ||
import com.fasterxml.jackson.jr.stree.JrSimpleTreeExtension; | ||
import com.fasterxml.jackson.jr.stree.JrsValue; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
@@ -36,7 +36,9 @@ public final class Jackson { | |
.disable(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY) | ||
.enable(JSON.Feature.PRETTY_PRINT_OUTPUT) | ||
.enable(JSON.Feature.READ_JSON_ARRAYS_AS_JAVA_ARRAYS) | ||
.treeCodec(new JacksonJrsTreeCodec()); | ||
.enable(JSON.Feature.USE_BIG_DECIMAL_FOR_FLOATS) | ||
.register(new JrSimpleTreeExtension()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just add a small comment here why we're adding |
||
|
||
|
||
mapperBuilder.streamFactory().enable(JsonParser.Feature.ALLOW_COMMENTS); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
* this interpreter make heavy use of the {@code JmesPathRuntime}. | ||
*/ | ||
public class JmesPathAcceptorGenerator { | ||
private static final ClassName BIG_DECIMAL = ClassName.get("java.math", "BigDecimal"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify this to |
||
private final ClassName runtimeClass; | ||
|
||
public JmesPathAcceptorGenerator(ClassName runtimeClass) { | ||
|
@@ -273,7 +274,7 @@ public void visitRawString(String input) { | |
public void visitLiteral(Literal input) { | ||
JrsValue jsonValue = input.jsonValue(); | ||
if (jsonValue.isNumber()) { | ||
codeBlock.add(".constant($L)", Integer.parseInt(jsonValue.asText())); | ||
codeBlock.add(".constant(new $T($S))", BIG_DECIMAL, jsonValue.asText()); | ||
} else if (jsonValue instanceof JrsBoolean) { | ||
codeBlock.add(".constant($L)", ((JrsBoolean) jsonValue).booleanValue()); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import static java.util.stream.Collectors.toList; | ||
import static java.util.stream.Collectors.toMap; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
@@ -47,9 +48,9 @@ public final class JmesPathRuntime { | |
private SdkPojo pojoValue; | ||
|
||
/** | ||
* The value if this is an {@link Type#INTEGER} (or null otherwise). | ||
* The value if this is an {@link Type#NUMBER} (or null otherwise). | ||
*/ | ||
private Integer integerValue; | ||
private BigDecimal numberValue; | ||
|
||
/** | ||
* The value if this is an {@link Type#STRING} (or null otherwise). | ||
|
@@ -105,9 +106,13 @@ public final class JmesPathRuntime { | |
} else if (value instanceof String) { | ||
this.type = Type.STRING; | ||
this.stringValue = (String) value; | ||
} else if (value instanceof Integer) { | ||
this.type = Type.INTEGER; | ||
this.integerValue = (Integer) value; | ||
} else if (value instanceof Number) { | ||
this.type = Type.NUMBER; | ||
if (value instanceof BigDecimal) { | ||
this.numberValue = (BigDecimal) value; | ||
} else { | ||
this.numberValue = new BigDecimal(value.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if (value instanceof Double || value instanceof Float) {
... |
||
} | ||
} else if (value instanceof Collection) { | ||
this.type = Type.LIST; | ||
this.listValue = new ArrayList<>(((Collection<?>) value)); | ||
|
@@ -143,7 +148,7 @@ public final class JmesPathRuntime { | |
switch (type) { | ||
case NULL: return null; | ||
case POJO: return pojoValue; | ||
case INTEGER: return integerValue; | ||
case NUMBER: return numberValue; | ||
case STRING: return stringValue; | ||
case BOOLEAN: return booleanValue; | ||
case LIST: return listValue; | ||
|
@@ -207,8 +212,8 @@ public final class JmesPathRuntime { | |
switch (type) { | ||
case NULL: | ||
return null; | ||
case INTEGER: | ||
return integerValue.toString(); | ||
case NUMBER: | ||
return numberValue.toString(); | ||
case STRING: | ||
return stringValue; | ||
case BOOLEAN: | ||
|
@@ -490,14 +495,14 @@ public final class JmesPathRuntime { | |
return new Value(false); | ||
} | ||
|
||
if (type == Type.INTEGER) { | ||
if (type == Type.NUMBER) { | ||
switch (comparison) { | ||
case "<": return new Value(integerValue < rhs.integerValue); | ||
case "<=": return new Value(integerValue <= rhs.integerValue); | ||
case ">": return new Value(integerValue > rhs.integerValue); | ||
case ">=": return new Value(integerValue >= rhs.integerValue); | ||
case "==": return new Value(Objects.equals(integerValue, rhs.integerValue)); | ||
case "!=": return new Value(!Objects.equals(integerValue, rhs.integerValue)); | ||
case "<": return new Value(numberValue.compareTo(rhs.numberValue) < 0); | ||
case "<=": return new Value(numberValue.compareTo(rhs.numberValue) <= 0); | ||
case ">": return new Value(numberValue.compareTo(rhs.numberValue) > 0); | ||
case ">=": return new Value(numberValue.compareTo(rhs.numberValue) >= 0); | ||
case "==": return new Value(numberValue.compareTo(rhs.numberValue) == 0); | ||
case "!=": return new Value(numberValue.compareTo(rhs.numberValue) != 0); | ||
default: throw new IllegalArgumentException("Unsupported comparison: " + comparison); | ||
} | ||
} | ||
|
@@ -635,7 +640,7 @@ public final class JmesPathRuntime { | |
MAP, | ||
BOOLEAN, | ||
STRING, | ||
INTEGER, | ||
NUMBER, | ||
NULL | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature doesn't need a changelog entry, since the changelog is for customer facing changes; this is more of an internal feature (though it does mean it will allow us to potentially offer more waiters for customers in the future).