Search in sources :

Example 1 with TextContainer

use of com.github.dreamhead.moco.parser.model.TextContainer in project moco by dreamhead.

the class FileContainerDeserializer method toFileContainer.

private FileContainer toFileContainer(final JsonParser jp) throws IOException {
    Iterator<FileVar> iterator = jp.readValuesAs(FileVar.class);
    FileVar file = get(iterator, 0);
    TextContainer filename = file.name;
    if (!isAllowedFilename(filename)) {
        throw new IllegalArgumentException("only string and template are allowed as filename");
    }
    return aFileContainer().withName(filename).withCharset(file.charset).build();
}
Also used : TextContainer(com.github.dreamhead.moco.parser.model.TextContainer)

Example 2 with TextContainer

use of com.github.dreamhead.moco.parser.model.TextContainer in project moco by dreamhead.

the class TextContainerDeserializerHelper method textContainer.

public TextContainer textContainer(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
    JsonToken currentToken = jp.getCurrentToken();
    if (currentToken == JsonToken.FIELD_NAME) {
        TextContainer.Builder builder = builder();
        String operation = jp.getText().trim();
        builder.withOperation(operation);
        JsonToken token = jp.nextToken();
        if (isForTemplate(operation) && token == JsonToken.START_OBJECT) {
            return template(jp, builder);
        }
        if (token == JsonToken.VALUE_STRING) {
            String text = jp.getText().trim();
            jp.nextToken();
            return builder.withText(text).build();
        }
    }
    return (TextContainer) ctxt.handleUnexpectedToken(TextContainer.class, jp);
}
Also used : TextContainer(com.github.dreamhead.moco.parser.model.TextContainer) JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

TextContainer (com.github.dreamhead.moco.parser.model.TextContainer)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1