小编xi.*_*lin的帖子

杰克逊为一个具有多态类型的字段定制解串器

更新:

我尝试在jackson源代码中调试并在方法中找出它

deserialize(JsonParser jp, DeserializationContext ctxt)

SettableBeanProperty.java

_valueTypeDeserializer它不为null时,它将永远不会使用_valueDeserializer.

这是一个正确的假设,TypeDeserializer应该比ValueDeserializer更合适吗?


我正在尝试使用@JsonDeserialize多态类型为一个字段定义自定义反序列化器.我可以成功地使用@JsonDeserialize@JsonTypeInfo分开.但是当我一起使用它们时,似乎@JsonDeserialize忽略了注释.

这是我的类层次结构:

1. Definition.java

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = Definition.class)
@JsonSubTypes({@Type(value = Definition.class, name = "normal"),
    @Type(value = FormDefinition.class, name = "form")})
public class Definition {

    private String name;
    private String description;

    // getter&setter for name&description
}
Run Code Online (Sandbox Code Playgroud)

2. FormDefinition.java

public class FormDefinition extends Definition {

    private String formName;
    @JsonDeserialize(using = DefinitionDeserializer.class)
    private …
Run Code Online (Sandbox Code Playgroud)

java polymorphism json jackson deserialization

21
推荐指数
1
解决办法
2万
查看次数

使用NSTextAttachment为NSAttributedString设置截断尾部的垂直对齐

我正在使用以下代码在iOS 8中生成NSAttributedStringfor UILabel.

// a long long Chinese title 
NSString *title = @"?????????????????????";
// setup icon attachment
NSTextAttachment *iconAttachment = [[NSTextAttachment alloc] init];
iconAttachment.image = [UIImage imageNamed:imageName];
iconAttachment.bounds = bounds;
NSAttributedString *ycardImageString = [NSAttributedString attributedStringWithAttachment:iconAttachment];

// setup attributed text
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:title];
if (shouldShowYcard) {
    [attributedText insertAttributedString:ycardImageString atIndex:0];
    [attributedText insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:1];
    [attributedText addAttribute:NSBaselineOffsetAttributeName value:@(offset) range:NSMakeRange(0, 1)];
}
NSRange titleRange = NSMakeRange(shouldShowYcard ? 2 : 0, title.length);
[attributedText addAttribute:NSFontAttributeName value:font range:titleRange];
[attributedText …
Run Code Online (Sandbox Code Playgroud)

alignment nsattributedstring uilabel nstextattachment ios

8
推荐指数
1
解决办法
673
查看次数

如何在Webpack构建中分析耗时的部分

我有一个由vue-cli创建的25个条目的小型VUE项目。

在开发过程中,打开HMR时,现在的重建时间约为10s。

--profile --progress用来启动webpack-dev-server,输出如下:

webpack: Compiling...
308ms building modules
50ms sealing
0ms optimizing
0ms basic module optimization
6ms module optimization
3ms advanced module optimization
53ms basic chunk optimization
0ms chunk optimization
0ms advanced chunk optimization
0ms module and chunk tree optimization
0ms chunk modules optimization
1ms advanced chunk modules optimization
13ms module reviving
0ms module order optimization
5ms module id optimization
6ms chunk reviving
3ms chunk order optimization
10ms chunk id optimization
44ms hashing
5ms module assets processing …
Run Code Online (Sandbox Code Playgroud)

performance webpack vue.js webpack-hmr vue-loader

7
推荐指数
1
解决办法
944
查看次数

core.hooksPath 可以有多个目录吗?

看来如果我core.hooksPath在全局配置文件中设置~/.gitconfig,里面的钩子$GIT_DIR/hooks将不会被执行。

我们可以在这两个文件夹中同时运行钩子吗?

git hook

6
推荐指数
1
解决办法
1671
查看次数

iOS 中有滑动返回手势的回调吗?

有时,当用户返回到上一个时UIViewController,我想做点什么。

如果用户单击 中的后退按钮UINavigationBar,我可以捕获该事件。

但如果他们使用向后滑动手势返回,我将无法响应更改。

那么滑动返回手势有回调吗?

目前我只能通过以下方式在我的应用程序中禁用此类页面

interactivePopGestureRecognizer.enabled = NO;
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller ios

5
推荐指数
1
解决办法
5584
查看次数

选择"颜色混合图层"时,UILabel标记为红色

我有一些backgroundColor白色或红色的UILabel ,不透明都是YES.

但是当Color Blended Layers在Simulator中选择该选项时,这些UILabel标记为红色而不是绿色.

还有哪些选择会导致这些?

我的代码如下:

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.senderNameLabel = [UILabel mt_labelWithFont:FONT(17) andColor:COLOR_NAV_TITLE];
        self.senderNameLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.senderNameLabel];

        self.actionTextLabel = [UILabel mt_labelWithFont:FONT(15) andColor:COLOR_NAV_TITLE];
        self.actionTextLabel.numberOfLines = 5;
        self.actionTextLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.actionTextLabel];

        self.notifyDateLabel = [UILabel mt_labelWithFont:FONT(12) andColor:COLOR_NAV_TITLE];
        self.notifyDateLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.notifyDateLabel];

        [self setLayoutConstraints];
    }
    return self;
}

- (void)setLayoutConstraints {
    CGFloat offsetX = 70;
    CGFloat offsetY = 15;
    CGFloat maxWidth = SCALE_WITH_RATIO(180); …
Run Code Online (Sandbox Code Playgroud)

uitableview uilabel ios-simulator

5
推荐指数
1
解决办法
1942
查看次数

在一个线程中休眠时使用GCD调度并发队列的规则

测试代码如下:

dispatch_queue_t queue = dispatch_queue_create("sc", DISPATCH_QUEUE_CONCURRENT);

dispatch_async(queue, ^{
    [NSThread sleepForTimeInterval:10];
    NSLog(@"10s --- %@", [NSThread currentThread]);
});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), queue, ^{
    NSLog(@"First: 5s --- %@", [NSThread currentThread]);
});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), queue, ^{
    NSLog(@"Second: 5s --- %@", [NSThread currentThread]);
});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), queue, ^{
    NSLog(@"Third: 5s --- %@", [NSThread currentThread]);
});
Run Code Online (Sandbox Code Playgroud)

在这里,我创建了一个并发队列,并使用异步方式睡眠一个线程.

但是,输出是:

2016-03-26 12:17:57.164 TestPlayground[28188:551287] 10s --- <NSThread: 0x7fa080511730>{number = 2, name = (null)}
2016-03-26 12:17:57.165 TestPlayground[28188:551287] First: 5s --- <NSThread: 0x7fa080511730>{number = 2, name …
Run Code Online (Sandbox Code Playgroud)

concurrency multithreading objective-c grand-central-dispatch thread-sleep

5
推荐指数
1
解决办法
883
查看次数

如何调试从后台回来时发生的崩溃

通过应用图标从后台回来时发生崩溃。

但是,我在控制台日志中看不到任何详细信息。有一个信号要终止,但是我们找不到信号号。

<FBApplicationProcess: 0x117bcb930; Maixxxx; pid: 1762> exited abnormally via signal.

Process exited: <FBApplicationProcess: 0x117bcb930; Maixxx; pid: -1> -> <FBApplicationProcessExitContext: 0x17103f820; exitReason: signal; terminationReason: (none)>
Run Code Online (Sandbox Code Playgroud)

控制台日志

重现崩溃的过程如下:

  1. 通过单击应用程序图标启动应用程序。
  2. 以普通用户身份使用该应用。
  3. 按主页将其置于背景中。
  4. 等待几分钟。
  5. 单击跳板屏幕上的应用程序图标,以再次使用它。
  6. 应用程序崩溃并退出。

由于崩溃仅在从后台返回时发生,并且需要进入后台几分钟,因此我无法在附加了lldb的调试模式下运行。

我没有使用任何背景功能。

另外,我在Fabric的Crashlytics中没有看到任何崩溃报告。因此,我认为不能同时调用信号处理程序吗?

如何调查这种问题?

crash debugging signals ios

5
推荐指数
1
解决办法
242
查看次数

我怎样才能获得uiimage的原始nsdata?

在我的应用程序中,用户可以从相册或相机中选择一张照片,在那里我可以获得uiimage表示.由于专辑可能有来自网络的图片,因此文件类型不仅仅是jpg.然后我需要将它发送到服务器而不转换.在这里我只能使用nsdata.
我知道UIImageJPEGRepresentation和UIImagePNGRepresentation,但我认为这两种方法可能会转换原始图像.也许当质量设置为1 UIImageJPEGRepresentation可以获得原始图片?
有没有什么方法可以获得原始的uiimage nsdata?

uiimage nsdata ios

1
推荐指数
1
解决办法
2985
查看次数

如何在使用AsyncDisplayKit时添加节头/页脚视图?

如此看来,目前ASTableNodeASTableView都缺乏的部分页眉/页脚视图支持.

我不仅可以找到一个协议方法:

- (nullable NSString *)tableNode:(ASTableNode *)tableNode titleForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)

什么都没有.

委托/ dataSource setter方法已被AsyncDisplayKit拦截,因此我无法使用UIKit的方式来执行此操作.

我在使用AsyncDisplayKit时可以添加节头/页脚视图吗?

uitableview sectionheader ios asyncdisplaykit

1
推荐指数
1
解决办法
898
查看次数