package com.fasterxml.jackson.databind.ser;

import java.io.IOException;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

public class TestJsonSerializeAs extends BaseMapTest
{
    // [JACKSON-799] stuff:
    public interface Fooable {
        public int getFoo();
    }

    // force use of interface
    @JsonSerialize(as=Fooable.class)
    public static class FooImpl implements Fooable {
        @Override
        public int getFoo() { return 42; }
        public int getBar() { return 15; }
    }

    public class Fooables {
        public FooImpl[] getFoos() {
            return new FooImpl[] { new FooImpl() };
        }
    }

    public class FooableWrapper {
        public FooImpl getFoo() {
            return new FooImpl();
        }
    }

    /*
    /**********************************************************
    /* Test methods
    /**********************************************************
     */

    private final ObjectWriter WRITER = objectWriter();

    // [JACKSON-799]
    public void testSerializeAsInClass() throws IOException
    {
        assertEquals("{\"foo\":42}", WRITER.writeValueAsString(new FooImpl()));
    }

    public void testSerializeAsForArrayProp() throws IOException
    {
        assertEquals("{\"foos\":[{\"foo\":42}]}", WRITER.writeValueAsString(new Fooables()));
    }

    public void testSerializeAsForSimpleProp() throws IOException
    {
        assertEquals("{\"foo\":{\"foo\":42}}", WRITER.writeValueAsString(new FooableWrapper()));
    }
}

@@ -232,36 +232,8 @@
 t%0A%7B%0A
-    // %5BJACKSON-799%5D stuff:%0A
     
@@ -518,32 +518,199 @@
 rn 15; %7D%0A    %7D%0A%0A
+    static class FooImplNoAnno implements Fooable %7B%0A        @Override%0A        public int getFoo() %7B return 42; %7D%0A        public int getBar() %7B return 15; %7D%0A    %7D%0A    %0A
     public class
@@ -942,24 +942,230 @@
    %7D%0A    %7D%0A%0A
+    // Also test via Field%0A    static class FooableWithFieldWrapper %7B%0A        @JsonSerialize(as=Fooable.class)%0A        public Fooable getFoo() %7B%0A            return new FooImplNoAnno();%0A        %7D%0A    %7D%0A    %0A
     /*%0A    /
@@ -1377,29 +1377,8 @@
 );%0A%0A
-    // %5BJACKSON-799%5D%0A
     
@@ -1424,36 +1424,32 @@
 rows IOException
-%0A   
  %7B%0A        asser
@@ -1578,36 +1578,32 @@
 rows IOException
-%0A   
  %7B%0A        asser
@@ -1638,16 +1638,32 @@
 :42%7D%5D%7D%22,
+%0A               
  WRITER.
@@ -1771,21 +1771,203 @@
 xception
+ %7B
 %0A    
+    assertEquals(%22%7B%5C%22foo%5C%22:%7B%5C%22foo%5C%22:42%7D%7D%22,%0A                WRITER.writeValueAsString(new FooableWrapper()));%0A    %7D%0A%0A    public void testSerializeWithFieldAnno() throws IOException 
 %7B%0A      
@@ -2006,16 +2006,32 @@
 %22:42%7D%7D%22,
+%0A               
  WRITER.
@@ -2053,32 +2053,41 @@
 ing(new FooableW
+ithFieldW
 rapper()));%0A    

add a unit test for serialization type overrides