Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
Fix #20
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 6, 2015
1 parent 56cc7bd commit f8da558
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-module-mrbean
= Releases
------------------------------------------------------------------------

2.5.2 (not yet released)

#20: Serialized beans have extra parameters in JSON
(reported by Craig B)

2.5.1 (06-Feb-2015)
2.5.0 (01-Jan-2015)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ protected void createField(ClassWriter cw, POJOProperty prop, TypeDescription ty
{
String sig = type.hasGenerics() ? type.genericSignature() : null;
String desc = type.erasedSignature();
FieldVisitor fv = cw.visitField(ACC_PUBLIC, prop.getFieldName(), desc, sig, null);
/* 15-Mar-2015, tatu: Should not be created public as that can cause problems
* like [mrbean#20]
*/
FieldVisitor fv = cw.visitField(ACC_PROTECTED, prop.getFieldName(), desc, sig, null);
fv.visitEnd();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public POJOProperty(String name, Class<?> ctxt)
{
_name = name;
_context = ctxt;
/* 06-Mar-2015, tatu: We used to use '_' prefix, but that leads to issues
* like [#20]; as well as prevents expected use without explicit setter.
*/
// Let's just prefix field name with single underscore for fun...
_fieldName = "_"+name;
_fieldName = name;
}

public String getName() { return _name; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.fasterxml.jackson.module.mrbean;

import com.fasterxml.jackson.databind.*;

public class RoundTripTest extends BaseTest
{
public interface Bean {
String getField();
void setField(String field);
}

public interface ReadOnlyBean {
String getField();
}

// [mrbean#20]: naming convention caused under-score prefixed duplicates
public void testSimple() throws Exception
{
ObjectMapper mapper = new ObjectMapper()
.registerModule(new MrBeanModule());
final String input = "{\"field\":\"testing\"}";
final Bean bean = mapper.readValue(input, Bean.class);
assertEquals("testing", bean.getField());
final String output = mapper.writeValueAsString(bean);
assertEquals(input, output);
}

public void testSimpleWithoutSetter() throws Exception
{
ObjectMapper mapper = new ObjectMapper()
.registerModule(new MrBeanModule());
final String input = "{\"field\":\"testing\"}";
final ReadOnlyBean bean = mapper.readValue(input, ReadOnlyBean.class);
assertEquals("testing", bean.getField());
final String output = mapper.writeValueAsString(bean);
assertEquals(input, output);
}
}

0 comments on commit f8da558

Please sign in to comment.