aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/main/java/org/onap/policy/common/utils/coder
AgeCommit message (Collapse)AuthorFilesLines
2023-02-20Clean up dependencies for London Releaseliamfallon1-1/+6
Issue-ID: POLICY-4482 Change-Id: Ibc0833313bf8eb5330c414ff00a31313500959e6 Signed-off-by: liamfallon <liam.fallon@est.tech>
2021-06-17Use lombok in policy-common utilsJim Hahn3-42/+11
Issue-ID: POLICY-3394 Change-Id: I42a18c115c3ca7110f37fc0ae8aeea3f2bbffb37 Signed-off-by: Jim Hahn <jrh3@att.com>
2021-05-06Fix sonars in policy-commonJim Hahn5-29/+28
Fixed sonars: - use "var" instead of actual type name - re-interrupt threads - use rej2 split() instead of String split() Issue-ID: POLICY-3285 Change-Id: I82261e0b8a53ee5c5264556fbf5cec37454f014e Signed-off-by: Jim Hahn <jrh3@att.com>
2021-04-13Revert "Modify StandardCoder to handle empty source"Jim Hahn1-22/+5
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-5/+22
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-12-14Convert YAML Double to Integer/LongJim Hahn2-3/+28
When a YAML number is decoded directly to type Object.class using the decode() or fromJson() methods of the StandardYamlCoder, the number is left as a Double. It should be converted to an Integer or Long, where possible. Issue-ID: POLICY-2900 Change-Id: I7707ac5c54167cbc3a4b23985c6e5fa1a507324e Signed-off-by: Jim Hahn <jrh3@att.com>
2020-04-06Address sonar issues in commonJim Hahn5-93/+47
Addressed the following sonar issues: - missing assertion in junit test case - disable sonars about setAccessible() as it's required for jackson emulation - sleep in junit - don't use wild-cards (e.g., "*") with java.util Pattern - use re2j instead of java.util Pattern - use String methods (e.g., startsWith()) - duplicate method bodies - duplicate code in Coder classes - string concatenation in logger calls - UTF-8 encoding - return primitive instead of boxed primitive - add assertion to tests - renamed support methods from doTestXxx to verifyXxx - cognitive complexity - use AtomicRef instead of volatile - use specific Functionals (e.g., IntConsumer) - function always returns the same value - serializable vs transient Issue-ID: POLICY-2305 Change-Id: I08eb7aa495a80bdc1d26827ba17a7946c83b9828 Signed-off-by: Jim Hahn <jrh3@att.com>
2020-03-24Sonar and eclipse warnings commonPamela Dragosh1-8/+6
Unused imports Not enough arguments Issue-ID: POLICY-2204 Change-Id: I6405cb697ea976096b1276e2291b1c73617d33b5 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
2020-03-03Add gson adapters for special field typesJim Hahn2-1/+126
Added type adapters for Instant, LocalDateTime, and ZonedDateTime. UUID seems to work already. Added new Coder that offers an alternative encoding for Instant. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I5230fa7fe955d78c5f2da1316cb1504b5875ea84
2020-02-17Add convert() to CoderJim Hahn2-1/+66
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-02-08Add enhancements to standard coderJim Hahn1-13/+57
Added support for array indices in StandardCoderObject getString(). Also made it Serializable. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: Ia514aed96fdfe7f635c5a6dc3e1f90939654d383
2020-01-31Add pretty() method to CoderJim Hahn4-8/+67
"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/+3
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
2020-01-27Schema validation extension to StandardCoderjhh2-6/+115
Issue-ID: POLICY-2331 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ic3e8d21715d17a61ea5d07740dd9f4dd0dbb8641 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
2019-10-29Fix new sonar issues in commonJim Hahn1-3/+3
Issue-ID: POLICY-2204 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: If0a11913f614e038ecd3e8c3f0b56d3ac78b03ec Signed-off-by: Jim Hahn <jrh3@att.com>
2019-10-29Merge "Cleanup eclipse warnings in common"Jorge Hernandez1-4/+0
2019-10-29Cleanup eclipse warnings in commonJim Hahn1-4/+0
Issue-ID: POLICY-2204 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: If55ea1a804997ab751f15813e6b643572d4f189f
2019-10-29Disable HTML escaping in gson codersJim Hahn1-4/+4
Issue-ID: POLICY-1869 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: Ic757d3a8e7e0e3537ecba979a919b9ea3c1aa797 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-10-24Integrate CryptoUtils into ONAP commonChou, Joseph (jc2555)1-0/+139
Update junit to add test cases Change-Id: If3236853138a05faac5f51a859b935265c14f0d6 Issue-ID: POLICY-1945 Signed-off-by: Chou, Joseph (jc2555) <jc2555@att.com>
2019-09-13Extract YamlJsonTranslator from StandardYamlCoderJim Hahn3-211/+330
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-09-12Remove YamlException classJim Hahn1-63/+0
After the implementation was finalized, it turned out that YamlException was no longer needed, so it has been deleted. Change-Id: Ie895fc096787f05eff36a6127b08247a7664ff8d Issue-ID: POLICY-2065 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-09-11Create StandardYamlCoderJim Hahn3-0/+348
Created StandardYamlCoder which is like a StandardCoder, except that the original converts to/from JSON, while the new class converts to/from YAML. Also added YamlMessageBodyHandler and incorporated it into the http server so that it supports a media type of */yaml. Change-Id: Ibd83a9f6d355a330f63e435f2bb41affcf1947c2 Issue-ID: POLICY-2065 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-07-17Convert double to int when decoding via gsonJim Hahn1-2/+20
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-2/+4
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 Hahn3-1/+166
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 Hahn2-1/+206
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 Hahn3-0/+174
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>