-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ignoreUnknownProperties option (#136)
* Add ignoreUnknownProperties option When Mattermost Server api response changed, you can suppress JsonMappingException by ignoreUnknownProperties = true by using MattermostClientBuilder#ignoreUnknownProperties(). * Add default constructor that use in~ ClientBuilder#register(Class<?>) * Add test cases * Update usage
- Loading branch information
1 parent
494d711
commit 05a089c
Showing
6 changed files
with
137 additions
and
6 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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
.../src/test/java/net/bis5/mattermost/jersey/provider/MattermostModelMapperProviderTest.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,57 @@ | ||
/* | ||
* Copyright (c) 2019 Takayuki Maruyama | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package net.bis5.mattermost.jersey.provider; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import com.fasterxml.jackson.core.JsonParseException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import javax.ws.rs.ext.ContextResolver; | ||
import net.bis5.mattermost.model.User; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test cases for {@link MattermostModelMapperProvider}. | ||
*/ | ||
public class MattermostModelMapperProviderTest { | ||
|
||
@Nested | ||
static class IgnoreUnknownPropertiesTest { | ||
private static final String JSON_INCLUDE_UNKNOWN_PROPERTY = // | ||
"{\"UNKNOWN_PROPERTY\":\"value\",\"id\":\"qjwhr6gcq3d8d883cgsuk17h9a\"}"; | ||
|
||
@Test | ||
public void ignoreUnknownPropertyCorrectly() | ||
throws JsonParseException, JsonMappingException, IOException { | ||
ContextResolver<ObjectMapper> provider = new MattermostModelMapperProvider(true); | ||
ObjectMapper objectMapper = provider.getContext(ObjectMapper.class); | ||
|
||
User user = objectMapper.readValue(JSON_INCLUDE_UNKNOWN_PROPERTY, User.class); | ||
assertNotNull(user); | ||
} | ||
|
||
@Test | ||
public void throwExceptionStrict() { | ||
ContextResolver<ObjectMapper> provider = new MattermostModelMapperProvider(false); | ||
ObjectMapper objectMapper = provider.getContext(ObjectMapper.class); | ||
|
||
assertThrows(JsonMappingException.class, | ||
() -> objectMapper.readValue(JSON_INCLUDE_UNKNOWN_PROPERTY, User.class)); | ||
} | ||
} | ||
} |