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

com.sap.cds.adapter.odata.v4.serializer.json.InlineCount2Json Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
/**************************************************************************
 * (C) 2019-2024 SAP SE or an SAP affiliate company. All rights reserved. *
 **************************************************************************/
package com.sap.cds.adapter.odata.v4.serializer.json;

import java.io.IOException;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.sap.cds.adapter.odata.v4.serializer.json.options.CdsODataOptions;

public class InlineCount2Json extends NavigationProperty2Json {

	private final CdsODataOptions options;

	public InlineCount2Json(String name, CdsODataOptions options) {
		this.navigationProperty = name;
		this.options = options;
	}

	@Override
	public void toJson(Map data, JsonGenerator json) throws IOException {
		String counterName = navigationProperty.concat("@count"); // TODO adapt, once representation in CDS4j is changed
		if (data.containsKey(counterName) && data.get(counterName) instanceof Long count) {
			String resultCounterName = navigationProperty + options.getConstants().getCount();
			if (options.isIEEE754Compatible()) {
				json.writeStringField(resultCounterName, count.toString());
			} else {
				json.writeNumberField(resultCounterName, count);
			}
			data.remove(counterName);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy