在JavaEE应用程序中注册Jackson MixIn(Register Jackson MixIn in JavaEE application)
在此设置的基础上(在JavaEE应用程序中使用Jackson作为JAXB提供程序): 如何注册我的MixIn模块 ?
在使用JAX-RS客户端功能的客户端应用程序中,它会自动注册。 我已经看过这个SO帖子 ,但是我从哪里获得ObjectMapper? 我试图在我的
ServletContextListener
创建并在那里注册模块。 但是当然,映射器实例将在contextInitialized
方法结束后处理。On the basis of this setup (using Jackson as JAXB-provider in a JavaEE application): How can I register my MixIn modules?
In my client application using the JAX-RS client feature it is registered automatically. I've seen this SO post, but where do I get the ObjectMapper from? I've tried to create on in my
ServletContextListener
and register the module there. But of course the mapper instance will be disposed after thecontextInitialized
method ends.
原文:https://stackoverflow.com/questions/29767579
最满意答案
使用单个类的原始映射,您可以执行以下操作:
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[User class]]; [mapping addAttributeMappingsFromDictionary:@{ @"user.FirstName": @"firstName", @"user.LastName": @"lastName", @"sessionToken" : @"sessionToken", }];
Using the original mapping with a single class you could do:
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[User class]]; [mapping addAttributeMappingsFromDictionary:@{ @"user.FirstName": @"firstName", @"user.LastName": @"lastName", @"sessionToken" : @"sessionToken", }];
相关问答
更多-
是的,RestKit可以在绘图时为您提供这种关系。 在您的Contact模型的RKManagedObjectMapping上,您需要执行以下操作: 添加一个关系映射到母公司: [objectMapping mapRelationship:@"company" withMapping:companyMapping] 将companyID属性映射到您的联系人模型上 确保您在这两个类上都配置了primaryKeyAttribute 指示RestKit来保存关系: [objectMapping connectRel ...
-
RestKit中的对象映射(Object Mapping in RestKit)[2022-06-07]
扎克,你应该在RestKit邮件列表上提出这个问题,并对你想要实现的目标更加具体。 无论如何,RestKit作者Blake Watters刚刚发布了一个描述对象映射的新文档 ,该文档应该回答您的所有问题。 祝你好运! Zach, you should probably ask this question on the RestKit mailing list and be a bit more specific as to what you want to achieve. Regardless, Rest ... -
使用RestKit进行对象映射(Object mapping with RestKit)[2022-06-11]
使用单个类的原始映射,您可以执行以下操作: RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[User class]]; [mapping addAttributeMappingsFromDictionary:@{ @"user.FirstName": @"firstName", @"user.LastName": @"lastName", @"sessionToken" : @"sessionToken", }]; Using th ... -
如果要将值存储为NSUUID则需要创建自定义值转换器以映射到该类或从该类映射。 如果您的字符串正确遵循UUID格式,因为NSUUID具有initWithUUIDString:和UUIDString方法,这将不是非常困难。 If you want to store your value as an NSUUID then you will need to create a custom value transformer to map to and from that class. This wouldn't ...
-
所以我找到了答案,在这一行: [registeredServicesMapping addAttributeMappingsFromDictionary:@{ @"registeredToServiceAntiVirus" : @"registeredToServiceAntiVirus", @"registeredToServiceCloud" : @"registeredTo ...
-
我只是有一个类似的问题:除了我映射到Core Data的用户对象外,我还需要获取返回的令牌。 令牌在JSON响应中自己发送,所以我不知道如何提取它。 最后我使用了以下内容: [operation setWillMapDeserializedResponseBlock:^id(id deserializedResponseBody) { NSDictionary *dictionary = [[NSMutableDictionary alloc] init]; dictionary = ...
-
RestKit:阻止getObjectsAtPath两次映射同一个对象(RestKit: prevent getObjectsAtPath from mapping the same object twice)[2023-11-16]
您无法阻止同一对象被映射两次,但性能影响类似于检查客户端上的更改。 你应该做的是将类似“最后请求日期”的内容传递给服务器,以便它可以过滤并仅返回适当的内容。 You can't prevent the same object from being mapped twice, but the performance impact is similar to checking for a change on the client side anyway. What you should really be do ... -
使用NSDictionary和NSArray对象进行RestKit映射(RestKit mapping with NSDictionary and NSArray object)[2022-02-11]
不要将description用作属性名称,它只会导致问题。 使用overview或类似的东西。 在JSON中,天气是一个数组,因此您应该将您的weather(info)属性设置为NSArray ,并确保映射中的名称和属性匹配。 I change the property of info object in "WeatherStatus" class to NSArray. @property (nonatomic, copy) NSString *name; @property (nonatomic, st ... -
RestKit - 无法找到keyPath的对象映射:''(RestKit - Could not find an object mapping for keyPath: '')[2022-06-07]
KeyPath不是json文件的名称,而是RestKit的起点: { "contact": { "nom": "whatever nom is", "prenom": "same for prenom", // ... } // ... } 在这种情况下,“contact”将是您的keyPath: [manager.mappingProvider setMapping:contactMapping forKeyPath:@"conta ... -
RestKit:测试对象映射,'映射时失败......'(RestKit: Testing object mapping, 'failure when mapping from…')[2023-05-09]
好吧,虽然令人尴尬,但我不会将解决方案发布到我的问题上。 我认为我的测试设置出了问题而不是我正在测试的代码是错的。 事实证明, 在我的json fixture中最后一个键值对的末尾有一个逗号 。 我手写了json fixture而不是直接从我的API输出中复制它。 因此,吸取的教训必须是: 将您尝试测试对象映射的json输出复制/粘贴到fixture文件中。 不要只是手工输入 - 可能会发生拼写错误等。 希望我是社区中唯一一个以这种方式做(或做过!)的人。 Okay, as embarrassing as ...