question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blackbird fails to deserialize varargs array

See original GitHub issue

The following code snippet fails. However, the same snippet works if either Blackbird is removed, or the constructor argument is changed to use double[] notation instead of double...

public class Scratch {
  public static void main(String[] args) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new BlackbirdModule());

    Foo foo = new Foo(new double[] { 1d, 2d, 3d });
    String serialized = mapper.writeValueAsString(foo);
    Foo foo2 = mapper.readValue(serialized, Foo.class);
  }

  static class Foo {

    @JsonProperty("bar")
    double[] bar;

    @JsonCreator
    public Foo(@JsonProperty("bar") double... bar) {
      this.bar = bar;
    }
  }
}
Exception in thread "main" com.fasterxml.jackson.databind.exc.ValueInstantiationException: Cannot construct instance of `com.alloymetrics.restapi.Scratch$Foo`, problem: class [D cannot be cast to class java.lang.Number ([D and java.lang.Number are in module java.base of loader 'bootstrap')
 at [Source: (String)"{"bar":[1.0,2.0,3.0]}"; line: 1, column: 21]
	at com.fasterxml.jackson.databind.exc.ValueInstantiationException.from(ValueInstantiationException.java:47)
	at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1907)
	at com.fasterxml.jackson.databind.DeserializationContext.handleInstantiationProblem(DeserializationContext.java:1260)
	at com.fasterxml.jackson.module.blackbird.deser.OptimizedValueInstantiator.createFromObjectWith(OptimizedValueInstantiator.java:51)
	at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:288)
	at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:202)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:454)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1405)
	at com.fasterxml.jackson.module.blackbird.deser.SuperSonicBeanDeserializer.deserializeFromObject(SuperSonicBeanDeserializer.java:247)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:195)
	at com.fasterxml.jackson.module.blackbird.deser.SuperSonicBeanDeserializer.deserialize(SuperSonicBeanDeserializer.java:116)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4593)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3548)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3516)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
stevenschlanskercommented, Jul 7, 2021

Thank you for the PR! I still want to take at least one attempt to optimize it, in case it turns out to be easy - but I will definitely borrow the test cases and this is a good fallback option if it turns out to be hard to optimize.

1reaction
stevenschlanskercommented, Jul 1, 2021

Strange, usually varargs and arrays behave the same, but there are a ton of edge cases. I am on vacation this week but can look next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bountysource
Blackbird fails to deserialize varargs array.
Read more >
jackson-module-guice-2.13.3-9.99.noarch.rpm openSUSE ...
... (blackbird) Blackbird fails to deserialize varargs array * 2.12.4 (06-Jul-2021) + #131: (afterburner) Failing to serialize 'Thread' returned by 'Thread.
Read more >
Varargs error when using Parameterized class in JUnit
a when you create method Object[] m(Object a) { return new Object[] { a }; } and change it to Arrays.asList(m(Translate.EN), m(Translate.FR)) ?...
Read more >
ecprice › Public › wordlist.ranked – MIT
... proposal birthday philadelphia sharing portal waiting fail gratis banking ... width noise engines forget array accurate discussed stephen elizabeth pin ...
Read more >
Untitled
... am-utils-6.2-Make-hasmntval-return-an-0-on-error-1-on-success.patch ... 0129-Added-the-missing-BANK_RAM-array-to-the-Commander-X1.patch ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found