Skip to content

Commit

Permalink
Support ignoring transient values (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanb authored and rhuss committed Jan 15, 2016
1 parent 61596c0 commit 6f485db
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
@@ -1,5 +1,6 @@
package org.jolokia.converter.json;

import java.beans.Transient;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.reflect.*;
Expand Down Expand Up @@ -206,7 +207,8 @@ private List<String> extractBeanAttributes(Object pValue) {
for (Method method : pValue.getClass().getMethods()) {
if (!Modifier.isStatic(method.getModifiers()) &&
!IGNORE_METHODS.contains(method.getName()) &&
!isIgnoredType(method.getReturnType())) {
!isIgnoredType(method.getReturnType()) &&
!method.isAnnotationPresent(Transient.class)) {
addAttributes(attrs, method);
}
}
Expand Down
@@ -1,5 +1,6 @@
package org.jolokia.converter.json;

import java.beans.Transient;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -146,6 +147,19 @@ public void setInnerValueTest() throws IllegalAccessException, AttributeNotFound
assertEquals(oldValue,"bar");
assertEquals(bean.getArray()[0],"fcn");
}

@Test
public void convertTransientValue() throws AttributeNotFoundException {
TransientValueBean bean = new TransientValueBean();
bean.value = "value";
bean.transientValue = "transient";

Map ret = (Map)converter.convertToJson(bean, null, JsonConvertOptions.DEFAULT);
System.out.println(ret);
assertNull(ret.get("transientValue"));

}

// ============================================================================
// TestBeans:

Expand Down Expand Up @@ -230,5 +244,30 @@ public String[] getArray() {
return array;
}
}

class TransientValueBean {

String value;

transient String transientValue;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

@Transient
public String getTransientValue() {
return transientValue;
}

@Transient
public void setTransientValue(String transientValue) {
this.transientValue = transientValue;
}
}
}

0 comments on commit 6f485db

Please sign in to comment.