-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing the Jackson leak in HttpHeaders, instead registering a separ…
…ate serializer directly with the JacksonAdapter. Tests that failed after functionality was removed from HttpHeaders now pass with the new HttpHeaderSerializer. (#4597)
- Loading branch information
1 parent
570632c
commit ea2f43a
Showing
3 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...src/main/java/com/azure/core/implementation/serializer/jackson/HttpHeadersSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.implementation.serializer.jackson; | ||
|
||
import com.azure.core.http.HttpHeaders; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Custom serializer for serializing {@code HttpHeaders} objects into Base64 strings. | ||
*/ | ||
final class HttpHeadersSerializer extends JsonSerializer<HttpHeaders> { | ||
/** | ||
* Gets a module wrapping this serializer as an adapter for the Jackson | ||
* ObjectMapper. | ||
* | ||
* @return a simple module to be plugged onto Jackson ObjectMapper. | ||
*/ | ||
public static SimpleModule getModule() { | ||
SimpleModule module = new SimpleModule(); | ||
module.addSerializer(HttpHeaders.class, new HttpHeadersSerializer()); | ||
return module; | ||
} | ||
|
||
@Override | ||
public void serialize(HttpHeaders value, JsonGenerator jgen, SerializerProvider provider) throws IOException { | ||
jgen.writeObject(value.toMap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters