aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java
AgeCommit message (Collapse)AuthorFilesLines
2021-05-21Enhance toString methods in factory classesJim Hahn1-6/+3
The factory classes in policy-endpoints have toString() methods that return "[]" for their list contents. Updated the code to provide a list of the keys rather than just an empty list. Also replaced some toString() methods with lombok. Also replace StringBuilder with concatenation in some cases. Issue-ID: POLICY-3298 Change-Id: I64fca21a4b009f7e09fcc482b5d156753fb7e680 Signed-off-by: Jim Hahn <jrh3@att.com>
2021-04-13Revert "Modify StandardCoder to handle empty source"Jim Hahn1-33/+2
This reverts commit 04623fef95f2b164d79ad48de2ef3708d02eda80. Reason for revert: prefer consistency with gson Issue-ID: POLICY-3172 Change-Id: Ic2501abcc68ec1186142a7e520e7985c43fd3315 Signed-off-by: Jim Hahn <jrh3@att.com>
2021-04-07Modify StandardCoder to handle empty sourceJim Hahn1-2/+33
Currently, if the source string or source file is empty, the StandardCoder just returns null. Modified it to throw an exception in those cases. However, if the string reference is null, it will still return null. Issue-ID: POLICY-3172 Change-Id: Ie7d5e1b0328a24d94a75af8d18a341faebbe5d5f Signed-off-by: Jim Hahn <jrh3@att.com>
2020-06-29Fix issues in common for new sonar rulesJim Hahn1-1/+4
Addressed issues reported due to updates to the sonar rules: - invoke only one method in a junit lambda - complete the assertion - add DOCTYPE to html Issue-ID: POLICY-2650 Change-Id: Ib8b8a2e4736cc23849c0f7aef972ffa3365a3e00 Signed-off-by: Jim Hahn <jrh3@att.com>
2020-02-17Add convert() to CoderJim Hahn1-1/+32
This addresses Liam's review comment about moving the "translate" method from the actor Util class into policy-common. Added a method to Coder to convert from one object type to another (e.g., from a Map to a POJO, or vice versa). Issue-ID: POLICY-2363 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I2a0b5ab4ce4b0eeda216a57cbe23a8bb64f64940
2020-01-31Add pretty() method to CoderJim Hahn1-0/+26
"Pretty" JSON is often needed, so added Coder.pretty() to facilitate that. Incorporated review comment(s): - changed pretty() to encode(object, pretty) Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I180fa6de416836008bf1c410132ae30f4dde9271
2020-01-29Convert double to int when decoding JSONJim Hahn1-1/+15
When decoding straight into a List or Map class, StandardCoder was not applying the double-to-int conversion. Fixed it. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I939e3378645d45ac98d2bca6b2a4076870a05626
2019-09-13Extract YamlJsonTranslator from StandardYamlCoderJim Hahn1-1/+23
Refactored StandardYamlCoder, extracting a new class, YamlJsonTranslator, from it. This facilitates performing yaml translation when not using a standard "gson" coder. Added YamlJacksonHandler which supports YAML translation layered on top of a JacksonHandler instead of a GsonMessageBodyHandler. Also added junit tests to complete coverage of StandardCoder. Also added public APPLICATION_YAML to YamlMessageBodyHandler. Change-Id: Ia470fa194661fbf1aebeaf0f18b57f2a984cb64b Issue-ID: POLICY-2081 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-07-17Convert double to int when decoding via gsonJim Hahn1-0/+9
Refactored MapDoubleAdapterFactory, extracting DoubleConverter to be used by code needing to convert Double to Integer/Long after being decoded by GSON. Enhanced StandardCoder to automatically use the above converter if the desired class is a generic Object. Change-Id: I1d4e83910de41ceda383f257bfea706db2b8fbbe Issue-ID: POLICY-1919 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-04-11Don't map JSON values to DoubleJim Hahn1-0/+26
By default, gson treats all numbers as Double when placed into a generic Map. This is not backward compatible with existing policy APIs. Added a type adapter that walks Map objects and converts the Double values to Integer or Long, where possible. Made this the default behavior in the GsonMessageBodyHandler, the JacksonHandler, and the StandardCoder. Also fixed a couple of checkstyle errors in the gson project. Change-Id: I9ac0c77e6592d1c039646f0662c077b77a1e9aaf Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-03-01Add StandardCoderObject to hide GSON internalsJim Hahn1-0/+48
Added StandardCoderObject to hide GSON's JsonElement so that classes are not dependent on the use of JsonElement, making it easier to switch out serialization mechanisms in the future. Added a test for field-not-found. Converted tabs to spaces in json test file. Simplified StandardCoderObject and added methods to Coder for translating to and from StandardCoderObject. Removed a test for a method that no longer exists. Added more tests to a test case. Change-Id: I5123dc3f17c940ded431ef7f9ccd8c4bff6b1c5f Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-02-27Add additional encode and decode methods to CoderJim Hahn1-14/+140
Also: Updated some comments and renamed a few parameters. Removed a "throws" for a RuntimeException. Short-circuit some calls. Typo in comment. Let gson create the JsonWriter. Renamed a few more parameters. Change-Id: I22e48c2191820c2a3d0743200edca79bd74353e7 Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-02-27Add common coder classesJim Hahn1-0/+73
Added coder classes as a common utility that can be used to encode and decode json data. Currently, it uses gson, but that can be changed. Separated the Coder interface from implementation. Used assertSame to compare references. Used numbers instead of strings so don't have to deal with escaping quotes in the test cases. Change-Id: Iea9001d2adc5a3150b3367619b5f43e96b5f8b41 Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>