首页 \ 问答 \ 在JavaEE应用程序中注册Jackson MixIn(Register Jackson MixIn in JavaEE application)

在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 the contextInitialized method ends.


原文:https://stackoverflow.com/questions/29767579
更新时间:2024-01-31 13:01

最满意答案

使用单个类的原始映射,您可以执行以下操作:

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邮件列表上提出这个问题,并对你想要实现的目标更加具体。 无论如何,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 ...
  • 使用单个类的原始映射,您可以执行以下操作: 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 = ...
  • 您无法阻止同一对象被映射两次,但性能影响类似于检查客户端上的更改。 你应该做的是将类似“最后请求日期”的内容传递给服务器,以便它可以过滤并仅返回适当的内容。 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 ...
  • 不要将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 ...
  • KeyPath不是json文件的名称,而是RestKit的起点: { "contact": { "nom": "whatever nom is", "prenom": "same for prenom", // ... } // ... } 在这种情况下,“contact”将是您的keyPath: [manager.mappingProvider setMapping:contactMapping forKeyPath:@"conta ...
  • 好吧,虽然令人尴尬,但我不会将解决方案发布到我的问题上。 我认为我的测试设置出了问题而不是我正在测试的代码是错的。 事实证明, 在我的json fixture中最后一个键值对的末尾有一个逗号 。 我手写了json fixture而不是直接从我的API输出中复制它。 因此,吸取的教训必须是: 将您尝试测试对象映射的json输出复制/粘贴到fixture文件中。 不要只是手工输入 - 可能会发生拼写错误等。 希望我是社区中唯一一个以这种方式做(或做过!)的人。 Okay, as embarrassing as ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)