Java URL Decode decodeStringFields(Object objBean, String code)

Here you can find the source of decodeStringFields(Object objBean, String code)

Description

decode String Fields

License

Open Source License

Declaration

public static void decodeStringFields(Object objBean, String code) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URLDecoder;

public class Main {
    public static void decodeStringFields(Object objBean, String code) {
        if (objBean == null) {
            return;
        }/*from   w  ww.j a va  2 s  .  c  o m*/
        Field[] fields = objBean.getClass().getDeclaredFields();
        String value = null;
        Object objValue = null;
        for (Field field : fields) {
            if (field.getType() == String.class) {
                try {
                    if (!Modifier.isPublic(field.getModifiers())) {
                        field.setAccessible(true);
                    }
                    objValue = field.get(objBean);
                    if (objValue != null) {
                        value = objValue.toString();

                        field.set(objBean, URLDecoder.decode(value, code));
                    }
                } catch (IllegalAccessException ex) {
                    ex.printStackTrace();
                } catch (UnsupportedEncodingException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}

Related

  1. decodeSpecialMdxCharactersInNames(String name)
  2. decodeStr(String str)
  3. decodeString(String cookedTextString)
  4. decodeString(String myString)
  5. decodeStringByUTF8(String str)
  6. decodeUTF8(String s)
  7. decodeValue(String str)
  8. decodeValue(String value)
  9. parseStringParamAndDecode(String inParam, String defaultVal, String charset)