首页 \ 问答 \ 从Jackson 2.2的ObjectMapper中打印JSON(Pretty printing JSON from Jackson 2.2's ObjectMapper)

从Jackson 2.2的ObjectMapper中打印JSON(Pretty printing JSON from Jackson 2.2's ObjectMapper)

现在我有一个org.fasterxml.jackson.databind.ObjectMapper的实例,并希望得到一个具有漂亮JSON的String 。 我的Google搜索的所有结果都提出了Jackson 1.x的这种做法,我似乎找不到适当的,不被弃用的方法,使用2.2。 即使我不认为代码对于这个问题是绝对必要的,这里是我现在所说的:

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
System.out.println("\n\n----------REQUEST-----------");
StringWriter sw = new StringWriter();
mapper.writeValue(sw, jsonObject);
// Want pretty version of sw.toString() here

Right now I have an instance of org.fasterxml.jackson.databind.ObjectMapper and would like to get a String with pretty JSON. All of the results of my Google searches have come up with Jackson 1.x ways of doing this and I can't seem to find the proper, non-deprecated way of doing this with 2.2. Even though I don't believe that code is absolutely necessary for this question, here's what I have right now:

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
System.out.println("\n\n----------REQUEST-----------");
StringWriter sw = new StringWriter();
mapper.writeValue(sw, jsonObject);
// Want pretty version of sw.toString() here

原文:https://stackoverflow.com/questions/17617370
更新时间:2022-06-15 14:06

最满意答案

[self setDelegate:self.superview];

这就是问题。

您应该将ViewController设置为委托的引用。

例如,在ViewController分配ImageDemoGridViewCell后,请按如下方式设置委托。

ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..];
cell.delegate = self;

然后将单元格作为子视图添加到ViewController的视图中。


[self setDelegate:self.superview];

This is the problem.

You should set the ViewController as the reference for the delegate.

For example, after you have allocated the ImageDemoGridViewCell in ViewController, set the delegate as follows.

ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..];
cell.delegate = self;

Then add the cell as subview to the ViewControllers view.

相关问答

更多
  • [self setDelegate:self.superview]; 这就是问题。 您应该将ViewController设置为委托的引用。 例如,在ViewController分配ImageDemoGridViewCell后,请按如下方式设置委托。 ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..]; cell.delegate = self; 然后将单元格作为子视图添加到ViewController的视图中。 ...
  • 这一行: [self.currentTextfield replaceRange:self.currentTextfield.selectedTextRange withText:entryString]; 不会导致对textField:shouldChangeCharactersInRange:replacementString:的调用textField:shouldChangeCharactersInRange:replacementString: 这是你所期待的吗? 由于您明确地更改了文本字段的文本 ...
  • 您需要在RatingViewController.m的viewDidLoad方法中设置委托。 委托不是按原样设置的,因为当调用initWithFrame:andRating: , _ratingViewController为nil 。 另外,在UIView引用UIViewController是不好的做法。 它不仅会创建一个保留周期,而且会忽略使用委托的一半原因:添加任何符合DelegateForSlider对象可以设置为StarRatingView的delegate属性的灵活性。 有关委托检查的更多信息,请 ...
  • 我怀疑问题在于你在VARendererViewController中初始化一个VASettingsView的新实例,而不是获得一个指向屏幕上的指针的指针。 由于您没有展示如何在屏幕上获得VASettingsView,或者您如何创建其视图,这只是一种猜测。 编辑后: 代替, VASettingsView *settingsView = [[VASettingsView alloc] init]; settingsView.delegate = self; 尝试这个, VASettingsView *sett ...
  • 我想你错过了一些东西。 你的声明是完美的,但你的电话是不正确的。 它应该如下... 视图控制器 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. LoginService *ls = [[LoginService alloc]init]; ls.delegate=self; [ls log ...
  • 好吧,我终于找到了问题。 在我的xib文件中,我将UIView类设置为自定义控件类名称,而不是设置文件所有者。 一旦我将xib中的第一个UIView改回到标准的UIView,然后将文件所有者设置为我的自定义类,那么所有的东西都是正确的! - 感谢所有试图帮助的人! Ok so I finally found the problem. In my xib file I had set the UIView class to my custom controls class name instead of se ...
  • SXMainController *mainController = [[SXMainController alloc] init]; self.delegate = mainController; [self.delegate detectAlgorihtm:self outputBufferValue:micBuffer withBufferSize:bufferSize]; 这段代码每次接收音频数据时都会创建一个新的viewController,这很可能不是您想要实现的。 你可能想要做的是在你创建了 ...
  • Objective-C将根据属性名称( enumType )而不是类型名称( MyEnumType )自动为您生成setter。 所以你的setter应该是以下代码: [self.mySampleTextField setEnumType:EnumTypeA]; Objective-C will automatically generate setter for you based on the name of the property (enumType) instead of the name of ...
  • 是的, viewdidload每次都会调用,因为您再次初始化选项卡。 setSelectedIndex从UITabbarcontroller类初始化tabbarcontroller evrytime。 你不应该从uitabbarcontroller类那样做。 只是初始化tabbarcontroller onece。 你不应该像这样使用tabbarcontroller 。 根据您的要求,您不需要使用tabbar只需在按钮单击时显示viewController 。 希望这会奏效。 Yes, viewdidloa ...
  • 您的GoogleLoginWrapper实例超出了viewDidLoad方法末尾的范围,因此会立即取消分配。 您无法使用您发布的代码调用sign...函数。 您应该使用属性而不是局部变量来保持对GoogleLoginWrapper实例的引用。 Your instance of GoogleLoginWrapper goes out of scope at the end of your viewDidLoad method so it is deallocated immediately. You can' ...

相关文章

更多

最新问答

更多
  • 您如何使用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)