java/webservice/src/main/java/be/bosa/dt/best/webservice/LookupResource.java
/**
	 * Convert multi(ple results) of addresses into JSON
	 * 
	 * @param info information about web request
	 * @param items entities
	 * @param embed add embedded part to JSON or not
	 * @return JSON object
	 */
Convert multi(ple results) of addresses into JSON

@param info information about web request
@param items entities
@param embed add embedded part to JSON or not
@return JSON object
Convert multi ( ple results ) of addresses into JSON @param info information about web request @param items entities @param embed add embedded part to JSON or not @return JSON object
private static JsonObject toJsonEmbeddable(UriInfo info, Multi<Address> items, boolean embed) {
		String self = info.getAbsolutePath().toString();
		Map<String,Street> streets = new HashMap<>();
		Set<String> embedded = new HashSet<>();
		JsonArray arr = new JsonArray();
		items.subscribe().asStream().forEach(a -> {
			String href = self + "/" + a.id.replace("/", "%2F");
			if (a.street != null) {
				streets.put(a.street.id, a.street);
			}
			embedded.add(a.mIdentifier);
			if (a.mpIdentifier != null) {
				embedded.add(a.mpIdentifier);
			}
			embedded.add(a.pIdentifier);
			arr.add(JsonObject.mapFrom(a).put("href", href));
		});
		JsonObject parentObj = new JsonObject();		
		parentObj.put("self", self);
		parentObj.put("items", arr); 
		if (embed) {
			JsonObject embObj = new JsonObject();
			streets.forEach((k,v) -> {
				JsonObject obj = JsonObject.mapFrom(v);
				embObj.put(obj.getString("self"), obj);
			});
			embedded.forEach(e -> { 
				JsonObject obj = cache.get(e);
				if (obj == null) {
					Log.errorf("%s not found in cache", e);
				} else {
					embObj.put(obj.getString("self"), obj);
				}
			});
			parentObj.put("embedded", embObj);
		}	
		return paginate(info, parentObj, arr);
	}
private static JsonObject toJsonEmbeddable ( UriInfo info , Multi < Address > items , boolean embed ) { String self = info . getAbsolutePath ( ) . toString ( ) ; Map < String , Street > streets = new HashMap < > ( ) ; Set < String > embedded = new HashSet < > ( ) ; JsonArray arr = new JsonArray ( ) ; items . subscribe ( ) . asStream ( ) . forEach ( a -> { String href = self + "/" + a . id . replace ( "/" , "%2F" ) ; if ( a . street != null ) { streets . put ( a . street . id , a . street ) ; } embedded . add ( a . mIdentifier ) ; if ( a . mpIdentifier != null ) { embedded . add ( a . mpIdentifier ) ; } embedded . add ( a . pIdentifier ) ; arr . add ( JsonObject . mapFrom ( a ) . put ( "href" , href ) ) ; } ) ; JsonObject parentObj = new JsonObject ( ) ; parentObj . put ( "self" , self ) ; parentObj . put ( "items" , arr ) ; if ( embed ) { JsonObject embObj = new JsonObject ( ) ; streets . forEach ( ( k , v ) -> { JsonObject obj = JsonObject . mapFrom ( v ) ; embObj . put ( obj . getString ( "self" ) , obj ) ; } ) ; embedded . forEach ( e -> { JsonObject obj = cache . get ( e ) ; if ( obj == null ) { Log . errorf ( "%s not found in cache" , e ) ; } else { embObj . put ( obj . getString ( "self" ) , obj ) ; } } ) ; parentObj . put ( "embedded" , embObj ) ; } return paginate ( info , parentObj , arr ) ; }
Convert multi(ple results) of addresses into JSON
Convert multi ( ple results ) of addresses into JSON