Expose MappingReader and MappingWriter

Jenkins Blue Ocean made interesting design choices relating github-api interactions.

They mostly reused the existing API and OM, but in a few places they chose to
implement their own object mapping independent of this project. This is fine
as long as nothing in this project ever changes, including internals such
as ObjectMapper configuration or behavior.

Recent release have made changes to those internals which break assumptions made
in Blue Ocean.

This change exposes this project's MappingReader and MappingWriter to allow
for a fix to Blue Ocean requiring only minimal changes.

This doesn't prevent future changes from breaking Blue Ocean but at least makes
them much less likely.

Fixes #780
This commit is contained in:
Liam Newman
2020-04-14 17:26:04 -07:00
parent 76c51922f1
commit e0aee9f361
10 changed files with 415 additions and 4 deletions

View File

@@ -8,8 +8,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.TimeZone;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.Is.is;
/**
@@ -131,6 +130,32 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
}
@Test
public void testMappingReaderWriter() throws Exception {
// This test ensures that data objects can be written and read in a raw form from string.
// This behavior is completely unsupported and should not be used but given that some
// clients, such as Jenkins Blue Ocean, have already implemented their own Jackson
// Reader and Writer that bind this library's data objects from outside this library
// this makes sure they don't break.
GHRepository repo = getTempRepository();
assertThat(repo.root, not(nullValue()));
String repoString = GitHub.getMappingObjectWriter().writeValueAsString(repo);
assertThat(repoString, not(nullValue()));
assertThat(repoString, containsString("testMappingReaderWriter"));
GHRepository readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString);
// This should never happen if these methods aren't used
assertThat(readRepo.root, nullValue());
String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(readRepo);
assertThat(readRepoString, equalTo(repoString));
}
static String formatDate(Date dt, String format) {
SimpleDateFormat df = new SimpleDateFormat(format);
df.setTimeZone(TimeZone.getTimeZone("GMT"));