package com.alibaba.json.bvt.taobao;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.ContextValueFilter;
import com.alibaba.fastjson.serializer.BeanContext;

import junit.framework.TestCase;

public class MTopTest extends TestCase {
    
    public void test_for_mtop() throws Exception {
        P0 p = new P0();
        p.model = new Model();
        
        ContextValueFilter valueFilter = new ContextValueFilter() {
            @Override
            public Object process(BeanContext context, Object object, String name, Object value) {
                Class<?> objectClass = context.getBeanClass();
                UrlIdentify annotation = context.getAnnation(UrlIdentify.class);
                
                if (value instanceof Model) {
                    return value;
                }
                
                return value;
            }
        };
        
        JSON.toJSONString(p, valueFilter);
    }

    private static class P0 {
        @UrlIdentify(schema="xxxx")
        private Model model;

        public Model getModel() {
            return model;
        }

        public void setModel(Model model) {
            this.model = model;
        }

    }

    public static class Model {
        private int id;
        private String url;

        
        public String getUrl() {
            return url;
        }

        
        public void setUrl(String url) {
            this.url = url;
        }


        
        public int getId() {
            return id;
        }


        
        public void setId(int id) {
            this.id = id;
        }
        
        
    }
    
    public static @interface UrlIdentify {
        String schema();
    }
}

@@ -42,33 +42,278 @@
 ort 
-com.alibaba.fastjson.JSON
+java.lang.annotation.Retention;%0Aimport java.lang.annotation.RetentionPolicy;%0Aimport java.lang.reflect.Field;%0A%0Aimport org.junit.Assert;%0A%0Aimport com.alibaba.fastjson.JSON;%0Aimport com.alibaba.fastjson.annotation.JSONField;%0Aimport com.alibaba.fastjson.serializer.BeanContext
 ;%0Aim
@@ -408,27 +408,33 @@
 ializer.
-BeanContext
+SerializerFeature
 ;%0A%0Aimpor
@@ -503,20 +503,16 @@
 tCase %7B%0A
-    
 %0A    pub
@@ -611,24 +611,16 @@
 odel();%0A
-        
 %0A       
@@ -676,24 +676,25 @@
 eFilter() %7B%0A
+%0A
             
@@ -798,24 +798,26 @@
 ct value) %7B%0A
+%0A%0A
             
@@ -824,30 +824,87 @@
     
-Class%3C?%3E objectC
+if (value instanceof Model) %7B%0A                    Assert.assertEquals(P0.c
 lass
- =
+,
  con
@@ -922,16 +922,17 @@
 nClass()
+)
 ;%0A      
@@ -945,135 +945,708 @@
     
-UrlIdentify annotation = context.getAnnation(UrlIdentify.class);%0A                %0A                if (value instanceof Model) %7B
+    Assert.assertNotNull(context.getField());%0A                    Assert.assertNotNull(context.getMethod());%0A                    Assert.assertEquals(%22model%22, context.getName());%0A                    Assert.assertEquals(Model.class, context.getFieldClass());%0A                    Assert.assertEquals(Model.class, context.getFieldType());%0A                    Assert.assertEquals(SerializerFeature.WriteMapNullValue.mask, context.getFeatures());%0A                    %0A                    Field field = context.getField();%0A                    Assert.assertNotNull(field.getAnnotation(UrlIdentify.class));%0A                    Assert.assertNotNull(context.getAnnation(UrlIdentify.class));%0A                    
 %0A   
@@ -1694,32 +1694,16 @@
       %7D%0A
-                
 %0A       
@@ -1750,24 +1750,16 @@
      %7D;%0A
-        
 %0A       
@@ -1830,16 +1830,90 @@
 ass P0 %7B
+%0A%0A        @JSONField(serialzeFeatures=SerializerFeature.WriteMapNullValue)
 %0A       
@@ -1932,17 +1932,19 @@
 y(schema
-=
+ = 
 %22xxxx%22)%0A
@@ -2170,16 +2170,17 @@
 Model %7B%0A
+%0A
         
@@ -2191,16 +2191,19 @@
 ate int 
+   
 id;%0A    
@@ -2227,25 +2227,16 @@
 g url;%0A%0A
-        %0A
         
@@ -2295,25 +2295,16 @@
      %7D%0A%0A
-        %0A
         
@@ -2371,34 +2371,24 @@
 %0A        %7D%0A%0A
-%0A        %0A
         publ
@@ -2438,26 +2438,16 @@
      %7D%0A%0A
-%0A        %0A
         
@@ -2514,36 +2514,55 @@
   %7D%0A
-        %0A        %0A    %7D%0A    
+%0A    %7D%0A%0A    @Retention(RetentionPolicy.RUNTIME)
 %0A   
@@ -2601,16 +2601,17 @@
 ntify %7B%0A
+%0A
         

add testcase for BeanContext