Skip to content

Commit

Permalink
Improve JSON for HTTP headers with a single value
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 13, 2024
1 parent 9cab722 commit 546fca8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.annotation.concurrent.Immutable;

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.datetime.PDTWebDateHelper;
import com.helger.commons.string.StringHelper;
import com.helger.json.IJsonArray;
Expand Down Expand Up @@ -89,8 +90,13 @@ public static IJsonObject getIncomingMetadataAsJson (@Nonnull final IAS4Incoming
final IJsonArray aArray = new JsonArray ();
for (final var aHeader : aMessageMetadata.getAllHttpHeaders ())
{
final ICommonsList <String> aHeaderValues = aHeader.getValue ();

final IJsonObject aObj = new JsonObject ();
aObj.add (aHeader.getKey (), new JsonArray ().addAll (aHeader.getValue ()));
if (aHeaderValues.size () != 1)
aObj.add (aHeader.getKey (), new JsonArray ().addAll (aHeaderValues));
else
aObj.add (aHeader.getKey (), aHeaderValues.getFirstOrNull ());
aArray.add (aObj);
}
if (aArray.isNotEmpty ())
Expand Down

0 comments on commit 546fca8

Please sign in to comment.