Git Product home page Git Product logo

Comments (4)

rowstop avatar rowstop commented on June 12, 2024

这是个不安全的特性,现在使用 AutoTypeBeforeHandler 、JSONReader.autoTypeFilter()实现

from fastjson2.

qingcaoDE avatar qingcaoDE commented on June 12, 2024

您看这样对吗 意思是 我不需要写这个枚举了直接带进来一个 指定类名前缀的autoTypeFilter就可以实现了吗

//当打开AutoTypeSupport,
// 虽然内置了一个比较广泛的黑名单,但仍然是不够安全的。
// 下面有一种办法是控制当前调用的AutoType支持范围,避免全局打开,这个更安全。
static final Filter autoTypeFilter = JSONReader.autoTypeFilter(
		// 按需加上需要支持自动类型的类名前缀,范围越小越安全
		"com.xxx"
);


@Override
public T deserialize(byte[] bytes) throws SerializationException {
	if (bytes == null || bytes.length <= 0) {
		return null;
	}
	String str = new String(bytes, DEFAULT_CHARSET);
	return JSON.parseObject(str, clazz, autoTypeFilter,
			JSONReader.Feature.FieldBased
	);
}

from fastjson2.

rowstop avatar rowstop commented on June 12, 2024

看起来是可以的,
com.alibaba.fastjson2.filter.ContextAutoTypeBeforeHandler#ContextAutoTypeBeforeHandler(boolean, java.lang.String...)
这里已经内置了一些类型的支持,额外的需要自己补充

from fastjson2.

qingcaoDE avatar qingcaoDE commented on June 12, 2024

好的 谢谢您

from fastjson2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.