Comments (6)
To test, I used:
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JacksonTest {
@Before
public void setUp() throws Exception {}
@Test
public void test() throws IOException {
Dog dog = new Dog();
dog.name = "Spike";
dog.legs = new ArrayList<Dog.Leg>();
dog.legs.add(dog.new Leg());
dog.legs.add(dog.new Leg());
dog.legs.get(0).length = 5;
dog.legs.get(1).length = 4;
ObjectMapper mapper = new ObjectMapper();
String dogJson = mapper.writeValueAsString(dog);
System.out.println(dogJson);
// output: {"name":"Spike","legs":[{length: 5}, {length: 4}]}
// currently throws JsonMappingException
Dog dogCopy = mapper.readValue(dogJson, Dog.class);
assertEquals(dogCopy.legs.get(1).length, 4);
// prefer fully populated Dog instance
}
public static class Dog
{
public String name;
public List<Leg> legs;
public class Leg {
public int length;
}
}
}
from jackson-core.
So to be clear, this doesn't work with properties that are collections (Lists) of inner classes, nor for 'normal' properties in conjunction with Inclusion.NON_DEFAULT
(the latter should possibly be a separate bug?).
from jackson-core.
Right, it has to be non-static inner class of "parent" class. Otherwise "implicit 'this'" is not known.
I have not tried this with Collections (like Lists) or Maps; it may just be omission due to differing JsonDeserializer implementations.
If you want to edit the title to reflect this, it should be possible to fix this. Although whether it can be done for 1.9.x is an open question (while it can be viewed as a bug, amount of refactoring work may mean it's impractical for 1.x).
from jackson-core.
(OK, it's midnight and I'm useless at coming up with plausible examples, but I've updated them anyway. I'm sorry Spike now has only 2 legs and they're different sizes, it was the best I could come up with...)
from jackson-core.
Hehe. Perfect. Oh. I need to move this to 'jackson-databind' (silly github without ability to share Issue trackers...).
Oh, also, this is good -- I assumed incorrectly that this was for non-static List type. Would have tried totally different test case.
from jackson-core.
Not sure if this can be supported actually. If there are still hopes for supporting this, please re-create for "jackson-databind" project, since that is where support would be added. This tracker is for streaming parser/generator.
from jackson-core.
Related Issues (20)
- Change default recycler pool to `newConcurrentDequePool()` in 2.18 HOT 1
- Change `JsonFactory.builder()` configuration of `RecyclerPool` to avoid allocation default implementation (in 3.0)
- Deprecate `LockFreePool` implementation in 2.18 (remove from 3.0) HOT 3
- Locale deserialization fails on locales with only a language and variant HOT 2
- `NUL`-corrupted keys, values on JSON serialization HOT 6
- Add back Java 22 optimisation in FastDoubleParser HOT 1
- Optimize `JsonParser.getDoubleValue()/getFloatValue()/getDecimalValue()` to avoid String allocation
- jackson-core-2.16.0.jar incorrectly flagged with CVE-2023-5072 (org.json library issue) HOT 3
- Add new method like `JsonParser.readText(Writer)` (and implementation) for truly non-buffering reads
- NegativeArraySizeException and ArrayIndexOutOfBoundsException in ByteQuadsCanonicalizer HOT 7
- How to change default RecyclerPool for 2.17.0 ? HOT 5
- info required for compatible version with openjdk21 HOT 2
- Demote `StreamReadConstraints` further down parser inheritance hierarchy
- Relax validation by `NumberInput.looksLikeValidNumber()` to allow trailing dot (like `3.`)
- Add new `StreamReadConstraints` (`maxTokenCount`) to limit maximum number of Tokens allowed per document HOT 1
- more JsonParser methods should declare throws HOT 7
- The JsonReyclerPools#LockFreePool object takes up a large amount of memory HOT 5
- After Jackson serializes a large number of objects, the metadata space of the JVM cannot be freed HOT 11
- JSON spec noncompliance: parsing multiple root objects HOT 3
- estimated release date for version 2.18 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-core.