Parse JSON with Java

Posted on by Kim

Using cxf to parse JSON

ChangeService changeService = JAXRSClientFactory.create(propertiesInterface.getServerUrl(),
        ChangeService.class, Collections.singletonList(new JacksonJaxbJsonProvider()),
        propertiesInterface.getUserName(), propertiesInterface.getPassword(), null);
Where ChangeService is
@Path("/change_request")
@Produces(MediaType.APPLICATION_JSON)
public interface ChangeService {

    @GET    public Changes getChangesByAssignedTo(
            @QueryParam("sysparm_query") String userSysId);
And maven dependency

    org.apache.cxf
    cxf-rt-rs-client
    ${cxf.version}
    provided


    org.codehaus.jackson
    jackson-jaxrs
    ${jackson.version}
    provided


    org.codehaus.jackson
    jackson-xc
    ${jackson.version}
    test

Build project automatically

Posted on by Kim

Split a URL into protocol, domain, port and uri using regular expressions

Posted on by Kim

// Split URL into protocol, domain, port and URI
Pattern pattern = ~/(https?:\/\/)([^:^\/]*)(:\d*)?(.*)?/
Matcher matcher = pattern.matcher url
matcher.find()

String protocol = matcher.group 1
String domain = matcher.group 2
String port = matcher.group 3
String uri = matcher.group 4