简体   繁体   English

在 Salesforce 中处理大型 JSON 物体

[英]Handling Large JSON bodies in Salesforce

Is there was way to digest large JSON bodies like you would with say a spring-boot project @JsonIgnoreProperties(ignoreUnknown=true) .有没有办法像你所说的 spring-boot 项目@JsonIgnoreProperties(ignoreUnknown=true)那样消化大型 JSON 身体。 Where you do not have to have a DTO in its entirety matching the JSON body?哪里不需要完全匹配 JSON 主体的 DTO? I recently hit some limits with this approach of 1:1(DTO:JSON) and I have not been successful in finding something that will allow me to ignore the massive JSON bodies(7MB and UP).我最近使用这种 1:1(DTO:JSON) 的方法遇到了一些限制,但我没有成功找到可以让我忽略大量 JSON 主体(7MB 及以上)的东西。 Thank you all for your input.谢谢大家的意见。

You could use JSON.deserialize(jsonString, apexType) .您可以使用JSON.deserialize(jsonString, apexType) Unlike JSON.deserializeStrict() this method just ignores unknown attributes instead of throwing an exception.JSON.deserializeStrict()不同,此方法只是忽略未知属性而不是抛出异常。
You could test it in developer console:您可以在开发人员控制台中对其进行测试:

String jsonString = '{ "unknown1": "aaa", "unknown2": "bbb", "type": "xyz", "id": "12345" }';
Data data = (Data) JSON.deserialize(jsonString, Data.class); // No Exception
System.debug(data);
try {
    Data data = (Data) JSON.deserializeStrict(jsonString, Data.class);
} catch(JSONException e) {
    System.debug('Exception thrown'); // You'll see this.
}

class Data {
    public String type;
    public String id;
}

Anyway if you have to handle more than 7MB of data, you should use an async transaction: the heap size limit is 6MB for synchronous one.无论如何,如果你必须处理超过 7MB 的数据,你应该使用异步事务:同步事务的堆大小限制为 6MB。 Governor Limits 调速器限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM