Transient fields are not written to TOML files by TomlWriter

Fixes #30
This commit is contained in:
Moandji Ezana 2016-06-14 19:51:22 -04:00
parent ab05197c9d
commit a37dfd80a8
3 changed files with 18 additions and 2 deletions

View File

@ -1,11 +1,15 @@
# toml4j Changelog
## 0.6.0 / 2016-05-09
## 0.6.0 / 2016-06-14
## Added
* Toml#toMap() convenience method (thanks to __[andytill](https://github.com/andytill)__ and __[Gyscos](https://github.com/Gyscos))
## Fixed
* Transient fields are not written to TOML files (thanks to __[lare96](https://github.com/lare96)__)
## 0.5.1 / 2016-01-24
### Fixed

View File

@ -50,7 +50,7 @@ class ObjectValueWriter implements ValueWriter {
Iterator<Field> iterator = fields.iterator();
while (iterator.hasNext()) {
Field field = iterator.next();
if ((Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) || field.isSynthetic()) {
if ((Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) || field.isSynthetic() || Modifier.isTransient(field.getModifiers())) {
iterator.remove();
}
}

View File

@ -455,6 +455,11 @@ public class TomlWriterTest {
private static class SimpleTestClass {
int a = 1;
}
private static class TransientClass {
int a = 2;
transient int b = 3;
}
@Test
public void should_write_to_writer() throws IOException {
@ -480,6 +485,13 @@ public class TomlWriterTest {
assertEquals("a = 1\n", readFile(output));
}
@Test
public void should_skip_transient_fields() throws Exception {
String toml = new TomlWriter().write(new TransientClass());
assertEquals("a = 2\n", toml);
}
@Test(expected = IllegalArgumentException.class)
public void should_refuse_to_write_string_fragment() {
new TomlWriter().write("fragment");