Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
support android mXXX fieldName. for issue 443. #443
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Apr 15, 2016
1 parent c5f27e7 commit 99fff2c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/alibaba/fastjson/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1441,9 +1441,16 @@ public static Field getField(Class<?> clazz, String fieldName, Field[] declaredF
if (field == null) {
field = getField0(clazz, "_" + fieldName, declaredFields);
}

if (field == null) {
field = getField0(clazz, "m_" + fieldName, declaredFields);
}

if (field == null) {
String mName = "m" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
field = getField0(clazz, mName, declaredFields);
}

return field;
}

Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/alibaba/json/bvt/android/MFieldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.alibaba.json.bvt.android;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import junit.framework.TestCase;

public class MFieldTest extends TestCase {

public void test_mfield() throws Exception {
VO vo = new VO();
vo.setName("xxx");

String text = JSON.toJSONString(vo);

Assert.assertEquals("{\"new_message\":\"xxx\"}", text);

VO vo1 = JSON.parseObject(text, VO.class);
Assert.assertEquals(vo.mName, vo1.mName);
}

public static class VO {

@JSONField(name = "new_message")
private String mName;

public String getName() {
return mName;
}

public void setName(String name) {
this.mName = name;
}

}
}

0 comments on commit 99fff2c

Please sign in to comment.