All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jdroid.javaweb.search.PagedResultJsonMarshaller Maven / Gradle / Ivy

The newest version!
package com.jdroid.javaweb.search;

import java.util.Map;
import com.jdroid.java.json.JsonMap;
import com.jdroid.java.marshaller.Marshaller;
import com.jdroid.java.marshaller.MarshallerMode;
import com.jdroid.java.search.PagedResult;
import com.jdroid.java.collections.CollectionUtils;

public class PagedResultJsonMarshaller implements Marshaller, JsonMap> {
	
	private static final String LAST_PAGE = "lastPage";
	private static final String LIST = "list";
	
	/**
	 * @see com.jdroid.java.marshaller.Marshaller#marshall(java.lang.Object, com.jdroid.java.marshaller.MarshallerMode,
	 *      java.util.Map)
	 */
	@Override
	public JsonMap marshall(PagedResult pagedResult, MarshallerMode mode, Map extras) {
		JsonMap map = new JsonMap(mode, extras);
		if (CollectionUtils.isNotEmpty(pagedResult.getResults())) {
			map.put(LAST_PAGE, pagedResult.isLastPage());
			map.put(LIST, pagedResult.getResults());
		}
		return map;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy