小编cri*_*shu的帖子

使用jQuery在多个promises之后等待完成

我想使用jquery的deferred/promise实现来排队多个异步ajax请求:

function doSomething() {
    console.log('doSomething')};

function makeMultiAjaxRequests1() {
    console.log('makeMultiAjaxRequests1')};

function makeMultiAjaxRequests2() {
    console.log('makeMultiAjaxRequests2')};

var step1 = function () { 
    var promise = new $.Deferred().promise();   
    makeMultiAjaxRequests1(); 
    return promise; }

var step2 = function () {
    var promise = new $.Deferred().promise();
    makeMultiAjaxRequests2();
    return promise; } 

step1()
   .then(step2())
   .done(doSomething());

$.when(step1(), 
       step2())
   .done(function () {
    doSomething();
});
Run Code Online (Sandbox Code Playgroud)

这是小提琴链接.所以我的问题是:

在并行执行step1和step2的模式中,代码没有到达最后一个处理函数.为什么?

javascript jquery asynchronous callback deferred

10
推荐指数
3
解决办法
2万
查看次数

杰克逊无法将空字符串值转换为枚举值

我正在寻找一个方便的解决方案与Jackson(2.8)在反序列化之前/期间筛选出指向空字符串值的字段:

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Guis {

public enum Context {
    SDS,
    NAVIGATION
}

public enum Layer {
    Library,
    Status,
    Drivingdata
}

// client code

 String s = "{\"context\":\"\",\"layer\":\"Drivingdata\"}";
 ObjectMapper mapper = new ObjectMapper();
 Guis o = mapper.readValue(s, Guis.class);
Run Code Online (Sandbox Code Playgroud)

错误

 Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type cq.speech.rsi.api.Guis$Context from String "": value not one of declared Enum instance names: [SDS NAVIGATION] at [Source: {"context":"","layer":"Drivingdata"}; line: 1, column: 12] (through reference chain: cq.speech.rsi.api.Guis["context"])
Run Code Online (Sandbox Code Playgroud)

还有什么我试过的......啊这一个

mapper.getDeserializationConfig().with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
Run Code Online (Sandbox Code Playgroud)

错误仍然存​​在,显然甚至谷歌搜索都没有多大帮助......

编辑

set …

java json jackson2

6
推荐指数
2
解决办法
1589
查看次数

标签 统计

asynchronous ×1

callback ×1

deferred ×1

jackson2 ×1

java ×1

javascript ×1

jquery ×1

json ×1