question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON interface is wrong for inner classes

See original GitHub issue

Please take the time to search the repository, if your question has already been asked or answered.

  • What version of the library are you using? Is it the latest version? The latest released version is Download

What kind of issue is this?

  • Question. Is this a question about how to do a certain thing?

  • Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests or steps to reproduce get fixed faster. Here’s an example: https://gist.github.com/swankjesse/6608b4713ad80988cdc9

    • spring xml/java config that is relevant
    • springfox specific configuration if it makes sense
    • include any output you’ve received; logs, json snippets etc.; and what the expected output should be
    • if you have a repo that demonstrates the issue for bonus points! See this example
  • Feature Request. Start by telling us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.

Please do consider starring this repository if you do like this project and find it useful.


Hello! When I implement response beans with inner class, unexpected JSON interface is displayed.

Book.class

@Data
public class Book {
	private Desc desc;

	@Data
	public class Desc {
		private String i_am_book_inner_class;
	}
}

Animal.class

@Data
public class Animal {
	private Desc desc;

	@Data
	public class Desc {
		private String i_am_animal_inner_class;
	}
}

Swagger Docs

{
  "desc": {
    "i_am_animal_inner_class": "string",
    "i_am_book_inner_class": "string"
  }
}

Here is my sample repository which can reproduce this behavior. It is simple Spring Boot jar so you can run by java -jar target/swaggerfox-bug-0.0.1-SNAPSHOT.jar after maven build.

Thank you.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, May 12, 2018

That is true… thanks for creating the repo. Im sure it will be very useful in validating #2056

0reactions
kkomissarchikcommented, May 27, 2021

This issue still exists in Springfox 3.0.0 release. Naming inner classes with the same name in different Java classes confuses the system, such that wrong JSON prototypes are shown for API requests and responses.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson Json Type Mapping Inner Class - java - Stack Overflow
The correct answer is that you are missing the static keyword on the inner class. Just make sure that the "static" keyword is...
Read more >
User guide is wrong: Inner classes can now be serialized ...
my hack was this : GsonBuilder gsonBuilder = new GsonBuilder(); final A a = new A(); gsonBuilder.registerTypeAdapter(A.class, (InstanceCreator) ...
Read more >
using static inner classes good or bad design ? — oracle-tech
Using lots of static inner classes is it a good design or not ? I am using inner classes to retrieve initialization variables...
Read more >
How can I create this JSON structure using inner classes?
I found the following question and answer, so I decided to give up on writeStringField and try JSON.serialize on inner classes instead.
Read more >
Using Java inner classes for Jackson serialization
Just add static keyword to your inner class. class ExampleClass { static class InnerClass { public int ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found