Search in sources :

Example 1 with Course

use of com.baeldung.protobuf.BaeldungTraining.Course in project tutorials by eugenp.

the class Application method createTestCourses.

@Bean
public CourseRepository createTestCourses() {
    Map<Integer, Course> courses = new HashMap<>();
    Course course1 = Course.newBuilder().setId(1).setCourseName("REST with Spring").addAllStudent(createTestStudents()).build();
    Course course2 = Course.newBuilder().setId(2).setCourseName("Learn Spring Security").addAllStudent(new ArrayList<>()).build();
    courses.put(course1.getId(), course1);
    courses.put(course2.getId(), course2);
    return new CourseRepository(courses);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Course(com.baeldung.protobuf.BaeldungTraining.Course) Bean(org.springframework.context.annotation.Bean)

Example 2 with Course

use of com.baeldung.protobuf.BaeldungTraining.Course in project tutorials by eugenp.

the class ApplicationIntegrationTest method convertProtobufMessageStreamToJsonString.

private String convertProtobufMessageStreamToJsonString(InputStream protobufStream) throws IOException {
    JsonFormat jsonFormat = new JsonFormat();
    Course course = Course.parseFrom(protobufStream);
    return jsonFormat.printToString(course);
}
Also used : JsonFormat(com.googlecode.protobuf.format.JsonFormat) Course(com.baeldung.protobuf.BaeldungTraining.Course)

Aggregations

Course (com.baeldung.protobuf.BaeldungTraining.Course)2 JsonFormat (com.googlecode.protobuf.format.JsonFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Bean (org.springframework.context.annotation.Bean)1