Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Forked from kawasima/SafeResolver.java
Last active October 3, 2020 02:40
Show Gist options
  • Save nakamura-to/11347570 to your computer and use it in GitHub Desktop.
Save nakamura-to/11347570 to your computer and use it in GitHub Desktop.
package example;
import org.apache.commons.beanutils.expression.DefaultResolver;
public class SafeResolver extends DefaultResolver {
@Override
public String next(String expression) {
String property = super.next(expression);
if ("class".equalsIgnoreCase(property)) {
return "";
}
return property;
}
}
package example;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.beanutils.BeanUtilsBean;
public class SafeResolverListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
SafeResolver resolver = new SafeResolver();
BeanUtilsBean.getInstance().getPropertyUtils().setResolver(resolver);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
}
}
@nakamura-to
Copy link
Author

うーん、gistってmention効かないみたいですね。

@glad2121
Copy link

describe でエラーになる件、これでどうですか?

public class SafeResolver extends DefaultResolver {

    public String next(String expression) {
        String property = super.next(expression);
        if ("class".equalsIgnoreCase(property)
                && !property.equals(expression)) {
            return "";
        }
        return property;
    }

}

@nakamura-to
Copy link
Author

この方法、うまく動きそうですね。

@bobbyjam99-zz
Copy link

describeを拡張しちゃいました。。。こっちのほうがスマートですね!

@uemuraj
Copy link

uemuraj commented May 30, 2014

describe の件、私は hasNested() もオーバーライドして "class" に対してだけ false を返すようにしてみました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment