Springfox/Swagger : Documenting HashMap object

People, I am trying to generate documentation for the spring services and I have one service which is like

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Map<String, Object>> getAccountList( HttpServletRequest request, HttpServletResponse response, ) { // Get account associate with user. List<Account> accounts = accountDB.findAccountForUser(user.getId()); // Create response object. Map<String, Object> responseObject = new LinkedHashMap<String, Object>(); responseObject.put(StringConstants.RESPONSE_TYPE, StringConstants.SUCCESS); responseObject.put(StringConstants.STATUS, HttpStatus.OK.value()); responseObject.put(StringConstants.ITEMS, mapAccountList(accounts)); return new ResponseEntity<Map<String, Object>>(responseObject, HttpStatus.OK); } private List<Map<String, String>> mapAccountList(List<Account> accountList) { List<Map<String, String>> accountMapList = new ArrayList<Map<String, String>>(); // Iterate over accountList and create map. for (Account account : accountList) { Map<String, String> accountMap = mapAccount(account); accountMapList.add(accountMap); } return accountMapList; }

Here, the problem is swagger is not generating a response information. In a case of POJO it works fine, but when I return a hashmap it does not.

Can any one help?

~Thanks.

-------------Problems Reply------------

When you have a map like you've defined it; it is a way of saying this is an any type in json. Specifically Map<String, Object> is rendered as an object. A more strongly typed type binding for the value like Account i.e Map<String, Account> will have different results (like what you're expecting).

Category:java Views:9 Time:2018-12-26

Related post

  • How can I combine two HashMap objects containing the same types? 2010-11-28

    I have two HashMaps defined like so: HashMap<String, Integer> map1 = new HashMap<String, Integer>(); HashMap<String, Integer> map2 = new HashMap<String, Integer>(); Also, I have a third HashMap object: HashMap<String, Integ

  • Efficient way to delete values from hashmap object 2011-01-15

    I have HashMap object contains a key x-y-z with corresponding value test-test1-test2. Map<String,String> map = new HashMap<String,String>(); map.put("x-y-z","test-test1-test2"); map.put("x1-y1-z1","test-test2-test3"); Now I have an input

  • JavaDoc-like documentation for Objective-C in Xcode? 2011-06-03

    Possible Duplicate: How to do the documentation in objective C? Is it possible to write class/method documentation in Objective-C in a way that Xcode 4 displays them in the quick help, and/or generates a doc document from it in the style of Apple's o

  • Sending a HashMap object to Java Servlet using C# 2011-10-17

    I have a Java Servlet application and I have a Java client that works. It simply creates a URLConnection object and an ObjectOutputStream and then just writes the Hashmap object. How do i do the same in C# since it has no "Hashmap" class. If I use so

  • How can one generate good documentation for object-oriented MATLAB code? 2011-10-20

    This question already has an answer here: How to document object-oriented MATLAB code? 4 answers I'm looking for a way to generate documentation for object-oriented MATLAB code. Using "doc classname" spits out exactly what I need (class header, prope

  • Where is the documentation for Objective-C++? 2011-11-18

    I know that Apple used to have a short documentation on Objective-C++ but now I cannot find it anywhere at all. Anyone who knows where to look? --------------Solutions------------- is this one? Objective C PDF - Apple Developer I know this is an old

  • Is it thread-safe to iterate a HashMap object concurrently? 2012-02-24

    If multiple threads concurrently iterate a HashMap object, without modifying it, is there a chance for race conditions? --------------Solutions------------- No race, if you can guarantee that no other thread would modify this HashMap while it is bein

  • Documentation for Objective C and Cocoa APIs? 2009-07-09

    Super-newbie question! I've been looking for a list of all the classes that come with Objective-C and Cocoa but can't seem to find one. Hoping that it has matching methods and syntax(?) as well. Be gentle with me! Thanks, Spencer. --------------Solut

  • I'm looking for some good documentation on Objective-J 2010-09-20

    I know Objective-J is very new and i also know Cappuccino API does some Ok documentation. I was looking for other information out there. I'm really looking to learn a new powerful web based language. Any Ideas? --------------Solutions------------- Be

  • Where can I find a good introduction or documentation on Objective-C blocks? 2010-12-10

    I am trying to use blocks in Objective-C. I've worked through this tutorial, but I would like to know more about blocks. Where should I look for better documentation or tutorials on Objective-C blocks and their usage? --------------Solutions---------

  • Documenting incomplete object graph of DTO object 2011-02-03

    The current architecture is based on WCF services which populate DTO objects from DB and return them. Some methods return complete object graph, some only partial. If completely populated, some object graphs would be extremely large - so that is not

  • Sorting HashMap objects on their properties rather values 2011-06-07

    This is not my real code I have just simulated in order to understand what to do next. I have class Person with properties age, height weight. Now In my class Group I create two four objects Person programmer, student, clerk, tech; I have HashMap rol

  • Returning hashmap objects instead of explicitly defined dto instances (bad practice?) 2011-08-25

    I found out that since JSON doesn't make a difference between hashes and objects, I can bypass the "law" of always sticking to dto classes, and instead return an "on-the-fly" hashmap, or a list of hashmaps, which will get JSON-serialized as a hash/es

  • Sum operator and HashMap object as the result 2012-02-17

    I have created a JPQL like this: select sum(c.field1) field1, sum(c.field2) field2, sum(c.field3) field3 from class c Now there are three problems: 1) I didn't find anywhere if I can use the synthax sum(c.field1) field1; 2) I didn't find anywhere if

  • Java - Extending HashMap - Object vs. generics behaviour 2012-04-27

    I'm writing a simple HashMap-based Cache that works as follows: If the requested key is in cache, return its value. If the requested key is not there, run a method that produces value based on key, store both, return value. The code: import java.util

  • Creating pointers out of HashMap objects in an object array 2013-01-31

    This is sort of an follow up to the first post I made, lets say I got two classes: public class Carinfo { private String carname; //The Carinfo[] value is set when making a new car //so for the object ford the array holds 3 null pointers private Cari

  • How to return HashMap object fields 2015-03-13

    I currently have the following HashMap in a Holiday class. Holiday Class: HashMap <String, Location> holidays = new HashMap<String, Location>(); This creates an instance of the Location class, to allow more fields to be shown. Location cl

  • Local Key/Value Store vs native dictionary/hashmap object 2011-12-27

    Any good reason to use something like Redis instead of a native dictionary collection, if you don't need persistence? Let's assume you have millions of entries, but they all fit comfortably in memory and you don't need durability. Am I right in think

  • HashMap(key: String, value: ArrayList) returns an Object instead of ArrayList? 2009-06-06

    I'm storing data in a HashMap with (key: String, value: ArrayList). The part I'm having trouble with declares a new ArrayList "current," searches the HashMap for the String "dictCode," and if found sets current as the returned value ArrayList. ArrayL

  • Access to key/values pairs of HashMaps within an Object[] 2011-02-02

    I have an Object[] which entails lots of Objects of the type HashMap. The HashMap looks like this: Object[] {id=15, name=Hello} {id=27, name=Hello} {id=15, name=Hello} I have tried to cast it to HashMap[], however no luck. I would like to iterate and

  • Is it better to use a custom Java object or to use a HashMaps to store data 2011-09-07

    Lets say we have a bunch of data (temp,wind,pressure) that ultimately comes in as a number of float arrays. For example: float[] temp = //get after performing some processing (takes time) float[] wind = Say we want to store these values in memory for

  • Accessing a HashMap of custom objects in request scope after a redirect 2011-12-08

    I have a HashMap of custom objects being passed to a JSP using RequestDispatcher and I am able to access the object and its properties using JSTL. However the code fails in case the parameter is sent using response.sendRedirect() . I am not sure what

  • How to access HashMap in JSP by Object key (rather than String) 2012-01-11

    I can access a HashMap<String, Object> easily enough in JSTL but is it possible to access a HashMap<Object, Object> I only ask because I don't receive any errors (or output) when trying the following: ${myHashMap[anObject]} It leads me to

  • How to retrive a List objects from HashMap and iterate in free marker template? 2012-04-14

    I have a Java Hashmap object which stores a key value pair in form of org.w3c.dom.Element: java.util.ArrayList. after populating the HashMap, I put it in Freemarker context along with List of org.w3c.dom.Element. When I try to get the List object usi

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.156 (s). 11 q(s)