• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / jsonschema2java / 18399814123

10 Oct 2025 07:35AM UTC coverage: 78.214% (-0.9%) from 79.157%
18399814123

push

github

torand
fix: bean validation annotations on primitive subtypes of compound pojo property types now generated

287 of 413 branches covered (69.49%)

Branch coverage included in aggregate %.

440 of 533 new or added lines in 26 files covered. (82.55%)

1 existing line in 1 file now uncovered.

808 of 987 relevant lines covered (81.86%)

4.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.53
/src/main/java/io/github/torand/jsonschema2java/writers/BaseWriter.java
1
/*
2
 * Copyright (c) 2024-2025 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.jsonschema2java.writers;
17

18
import io.github.torand.jsonschema2java.generators.Options;
19
import io.github.torand.jsonschema2java.utils.JsonSchema2JavaException;
20

21
import java.io.IOException;
22
import java.io.Writer;
23

24
/**
25
 * Base class for all code writers.
26
 */
27
public abstract class BaseWriter implements AutoCloseable {
28

29
    private final Writer writer;
30

31
    /**
32
     * The plugin options.
33
     */
34
    protected final Options opts;
35

36
    /**
37
     * Constructs a {@link BaseWriter} object.
38
     * @param writer the java io writer to wrap.
39
     * @param opts the plugin options.
40
     */
41
    protected BaseWriter(Writer writer, Options opts) {
2✔
42
        this.writer = writer;
3✔
43
        this.opts = opts;
3✔
44
    }
1✔
45

46
    /**
47
     * Writes a formatted string without end-of-line.
48
     * @param format the format.
49
     * @param args the arguments.
50
     */
51
    protected void write(String format, Object... args) {
52
        try {
53
            writer.append(format.formatted(args));
7✔
54
        } catch (IOException e) {
×
NEW
55
            throw new JsonSchema2JavaException("Failed to append to writer", e);
×
56
        }
1✔
57
    }
1✔
58

59
    /**
60
     * Writes a formatted string with end-of-line.
61
     * @param format the format.
62
     * @param args the arguments.
63
     */
64
    protected void writeLine(String format, Object... args) {
65
        try {
66
            writer.append(format.formatted(args)).append("\n");
9✔
67
        } catch (IOException e) {
×
NEW
68
            throw new JsonSchema2JavaException("Failed to append to writer", e);
×
69
        }
1✔
70
    }
1✔
71

72
    /**
73
     * Writes end-of-line.
74
     */
75
    protected void writeNewLine() {
76
        try {
77
            writer.append("\n");
5✔
78
        } catch (IOException e) {
×
NEW
79
            throw new JsonSchema2JavaException("Failed to append to writer", e);
×
80
        }
1✔
81
    }
1✔
82

83
    /**
84
     * Writes specified number of indent levels.
85
     * @param levels the number of indent levels.
86
     */
87
    protected void writeIndent(int levels) {
88
        String indent = "\t";
2✔
89
        if (!opts.indentWithTab()) {
4!
90
            indent = " ".repeat(opts.indentSize());
6✔
91
        }
92

93
        for (int level = 0; level < levels; level++) {
7✔
94
            try {
95
                writer.append(indent);
5✔
96
            } catch (IOException e) {
×
NEW
97
                throw new JsonSchema2JavaException("Failed to append to writer", e);
×
98
            }
1✔
99
        }
100
    }
1✔
101

102
    @Override
103
    public void close() throws IOException {
104
        writer.close();
3✔
105
    }
1✔
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc