json-annotation | quickest way to add a JSON format | JSON Processing library
kandi X-RAY | json-annotation Summary
kandi X-RAY | json-annotation Summary
The @json scala macro annotation is the quickest way to add a JSON format to your Play project's case classes.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of json-annotation
json-annotation Key Features
json-annotation Examples and Code Snippets
Community Discussions
Trending Discussions on json-annotation
QUESTION
Jackson annotations applied to POJOs exported through an OSGi depdendency does not work when the POJO is serialized in an importing bundle at Runtime. If the POJO is placed in the using bundle directly, or tested in a Unit Test (in either bundle), everything works as expected.
Does anyone know what could make the runtime serialization ignore the Jackson-annotations at runtime in the importing OSGi-bundle?
This is a looong question. I have tried to create an as simple example as possible. If anything is unclear, please let me know, and I will try to elaborate.
Contents
Inside Exporting Bundle
- POJO
- Unit test (which works)
- Runtime test (which works)
Inside Importing Bundle
- Unit test (which works)
- Runtime test (which FAILS)
Runtime environment details
- Bundle manifests (simplified)
Let's assume we have want to serialize a simple POJO exported and imported over OSGi. The JSON-annotations should work both in the importing and exporting bundle, both runtime and during unit tests (runtime fails in the when imported).
Inside Exporting Bundle:Both runtime and unit tests of the Jackson serialization works just fine in the bundle where the POJO itself is declared.
POJO to serialize
The @JsonProperty
-annotation should make any serialized version of this POJO look something like {"correctSerializedName":"someName"}
and not {"javaName":"someName"}
:
ANSWER
Answered 2018-Jun-13 at 15:01Based on my comments and your feedback:
The problem is that your two bundles have different instances of the Jackson annotation classes. When the Jackson framework scans classes for annotations, it looks for the specific annotation class instance that it uses. If a bundle has its own instance of the same class, the annotation will not be recognised. (In OSGi, each bundle has a separate class loader, and each class loader can contain its own instance of a given class.)
You can resolve this in two ways:
- Deploy jackson2 as separate bundles to your OSGi container, and ensure that both your importing and exporting bundle have
Import-Package
on the relevant jackson packages. The most central bundles are:jackson-annotations
,jackson-core
andjackson-databind
. In this case, use scopeprovided
for the jackson2 dependencies in both your bundles. - Export the jackson2 packages from one of your bundles, and import it in the other. This will give you the extra work of figuring out and maintaining which packages to export. In this case, use scope
compile
for jackson2 in the exporting bundle, and scopeprovided
in the importing bundle.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install json-annotation
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page