package com.fasterxml.jackson.failing;

import java.math.BigDecimal;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.*;

public class JDKNumberDeser2644Test extends BaseMapTest
{
    // [databind#2644]
    static class NodeRoot2644 {
        public String type;

        @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
        @JsonSubTypes(value = {
                @JsonSubTypes.Type(value = NodeParent2644.class, name = "NodeParent")
        })
        public Node2644 node;
    }

    public static class NodeParent2644 extends Node2644 { }

    public static abstract class Node2644 {
        @JsonProperty("amount")
        BigDecimal val;

        public BigDecimal getVal() {
            return val;
        }

        public void setVal(BigDecimal val) {
            this.val = val;
        }
    }

    // [databind#2644]
    public void testBigDecimalSubtypes() throws Exception
    {
        ObjectMapper mapper = newJsonMapper();

        // NOTE: uncommenting this does work around the issue:
//        mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
        mapper.registerSubtypes(NodeParent2644.class);

        NodeRoot2644 root = mapper.readValue(
                "{\"type\": \"NodeParent\",\"node\": {\"amount\": 9999999999999999.99} }",
                NodeRoot2644.class
        );

        assertEquals(new BigDecimal("9999999999999999.99"), root.node.getVal());

    }

}

@@ -258,20 +258,129 @@
 son.
-databind.*;%0A
+annotation.JsonUnwrapped;%0Aimport com.fasterxml.jackson.databind.*;%0A%0A// Tests for%0A//%0A// %5Bdatabind#2644%5D%0A// %5Bdatabind#2785%5D
 %0Apub
@@ -1118,24 +1118,251 @@
    %7D%0A    %7D%0A%0A
+    // %5Bdatabind#2785%5D%0A    static class BigDecimalHolder2785 %7B%0A        public BigDecimal value;%0A    %7D%0A%0A    static class NestedBigDecimalHolder2785 %7B%0A        @JsonUnwrapped%0A        public BigDecimalHolder2785 holder;%0A    %7D%0A    %0A
     // %5Bdata
@@ -1944,18 +1944,690 @@
 Val());%0A
-%0A
     %7D%0A%0A
+    // %5Bdatabind#2785%5D%0A   %0A    public void testBigDecimalUnwrapped() throws Exception%0A    %7B%0A        final ObjectMapper mapper = newJsonMapper();%0A        // mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);%0A        final String JSON = %22%7B%5C%22value%5C%22: 5.00%7D%22;%0A%0A        // first simple working case:%0A        BigDecimalHolder2785 holder = mapper.readValue(JSON, BigDecimalHolder2785.class);%0A        assertEquals(new BigDecimal(%225.00%22), holder.value);%0A%0A        // and then one that doesn't%0A        NestedBigDecimalHolder2785 result = mapper.readValue(JSON, NestedBigDecimalHolder2785.class);%0A        assertEquals(new BigDecimal(%225.00%22), result.holder.value);%0A    %7D%0A
 %7D%0A

Add failing test for #2785